因为Struts2是线程安全的,每次请求的时候都会创建一个Action实例,在与spring集成的时候,基于注解,必须在控制器中加入@Scope("prototype")代码。
再研究Struts2的时候出现以下问题:
Java代码
- Exception starting filter struts2
- Action class [LogAction] not found - action - file:/E:/software/apache-tomcat-6.0.16/webapps/ROOT/WEB-INF/classes/struts.xml:30:51
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:374)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:329)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:429)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:239)
- at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
- at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
- at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
- at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
- at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
- at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:201)
- at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
- at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
- at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
- at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
- at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
- at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
- at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
- at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:924)
- at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:887)
- at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
- at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
- at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
- at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
- at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
- at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
- at org.apache.catalina.core.StandardService.start(StandardService.java:516)
- at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
- at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
- 2009-5-21 15:05:02 org.apache.catalina.core.StandardContext start
- Exception starting filter struts2
- Action class [LogAction] not found - action - file:/E:/software/apache-tomcat-6.0.16/webapps/ROOT/WEB-INF/classes/struts.xml:30:51
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:374)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:329)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:429)
- at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:239)
- at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
- at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
- at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
- at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
- at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
- at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:201)
- at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
- at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
- at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
- at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
- at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
- at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
- at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
- at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:924)
- at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:887)
- at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
- at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
- at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
- at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
- at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
- at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
- at org.apache.catalina.core.StandardService.start(StandardService.java:516)
- at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
- at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
- 2009-5-21 15:05:02 org.apache.catalina.core.StandardContext start
struts.xml中是这样配置的
Java代码
- <context:component-scan base-package="net.shopin"/>
- <action name="*" class="LogAction" method="{1}">
- <result name="login">/WEB-INF/page/member/login.jsp</result>
- </action>
- <context:component-scan base-package="net.shopin"/>
- <action name="*" class="LogAction" method="{1}">
- <result name="login">/WEB-INF/page/member/login.jsp</result>
- </action>
以为以上用到了spring的自动扫描工程中的bean,所以class那写的不是bean的全名,研究了好久才发现原来class那写的时候,***个字母必须小写,改后,问题解决……
修改后的struts.xml
Java代码
- <context:component-scan base-package="net.shopin"/>
- <action name="*" class="logAction" method="{1}">
- <result name="login">/WEB-INF/page/member/login.jsp</result>
- </action>
【编辑推荐】