Struts2 SEOActionNameBuild (The action name cannot be the same as the action suffix [Action]) 终极解决方案
2011-08-09 10:21
706 查看
最近正好在做一个电子商务网站的二次研发,由于需要植入与移动平台对接的SNS系统,客户提出在保留原有项目功能基础上实施扩展,并且要求使用Struts2研发,旧系统模块使用的是Struts1,在直接导入Struts2 jar包后系统发生如下异常:
由于错误名字异常诡异,因此并未立刻解决,google了老半天国外论坛也没结果,于是准备着手自己解决,首先查看了源代码SEOActionNameBuilder
的源代码发现抛出异常的主要原因是以下这句语句:
那么问题是怎么会导致这个判断成立的呢?
原来Struts的辅助控制器的父类就叫Action,而Struts是属于拦截器机制的,因此很可能会不通过配置文件,而通过拦截请求找到该类,为了证实想法,使用
log4j.properties打印启动[Debug]日志发现
PackageBasedActionConfigBuilder 会解析所有与Action有关的类,于是寻找给类得位置,该类隶属于org.apache.struts2.convention包
那么如果能够禁止PackageBasedActionConfigBuilder 的自动解析,或者禁止该类调用Action那么异常就不会发生了。
找到该类在struts-convention-plugin.jar的struts-plugin.xml中配置,从名字看这是一个可有可无的插件包
打开文件找到以下语句:
原来问题出在这个文件的配置,该文件明确表明了会检索以action,actions,struts,struts2的名字检索对应的jar包,那么org.apache.struts.Action自然而然会被解析。
发生异常也是理所当然的,那么我们打开自己的struts.xml文件修改常量,因为项目的struts.xml的配置是高于
插件配置的,更改如下:
表示插件只对actions和struts2包感兴趣,于是乎异常被解决了。
当然如果表示对使用(struts-convention-plugin.jar)压力很大的童鞋们,可以考虑直接删除该jar包不使用,异常一样可以解决。
最后要说的是:
Struts2和Struts1并存一个项目,功能无互访性,而且也不发生Struts2组件调用Struts1的Action的话,没必要使用struts2提供的Struts1-plugin组件实施集成的。
而且发生这个异常也不要想当然的认为将所有Action类得名字中去除Action关键字就能解决。
Line: 64 - org/apache/struts2/convention/SEOActionNameBuilder.java:64:-1 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51) 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) Caused by: java.lang.IllegalStateException: The action name cannot be the same as the action suffix [Action] at org.apache.struts2.convention.SEOActionNameBuilder.build(SEOActionNameBuilder.java:64) at org.apache.struts2.convention.PackageBasedActionConfigBuilder.determineActionName(PackageBasedActionConfigBuilder.java:712) at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:535) at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318) at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418) ... 29 more 2011-8-9 10:22:11 org.apache.catalina.core.StandardContext start 严重: Error filterStart 2011-8-9 10:22:11 org.apache.catalina.core.StandardContext start |
的源代码发现抛出异常的主要原因是以下这句语句:
if (actionName.equals(actionSuffix)) throw new IllegalStateException("The action name cannot be the same as the action suffix ["+ actionSuffix + "]"); |
原来Struts的辅助控制器的父类就叫Action,而Struts是属于拦截器机制的,因此很可能会不通过配置文件,而通过拦截请求找到该类,为了证实想法,使用
log4j.properties打印启动[Debug]日志发现
PackageBasedActionConfigBuilder 会解析所有与Action有关的类,于是寻找给类得位置,该类隶属于org.apache.struts2.convention包
那么如果能够禁止PackageBasedActionConfigBuilder 的自动解析,或者禁止该类调用Action那么异常就不会发生了。
找到该类在struts-convention-plugin.jar的struts-plugin.xml中配置,从名字看这是一个可有可无的插件包
打开文件找到以下语句:
<constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/> <constant name="struts.convention.package.locators.disable" value="false"/> <constant name="struts.convention.package.locators.basePackage" value=""/> <constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*, org.springframework.web.struts.*, org.springframework.web.struts2.*, org.hibernate.*"/> |
发生异常也是理所当然的,那么我们打开自己的struts.xml文件修改常量,因为项目的struts.xml的配置是高于
插件配置的,更改如下:
<constant name="struts.convention.package.locators" value="actions,struts2"/> |
当然如果表示对使用(struts-convention-plugin.jar)压力很大的童鞋们,可以考虑直接删除该jar包不使用,异常一样可以解决。
最后要说的是:
Struts2和Struts1并存一个项目,功能无互访性,而且也不发生Struts2组件调用Struts1的Action的话,没必要使用struts2提供的Struts1-plugin组件实施集成的。
而且发生这个异常也不要想当然的认为将所有Action类得名字中去除Action关键字就能解决。
相关文章推荐
- Struts2 SEOActionNameBuild (The action name cannot be the same as the action suffix [Action]) 终极解决方案
- The action name cannot be the same as the action suffix [Action]遇到此有关问题的解决办法
- 从AS导入Eclipse项目,报Error:Application and test application id cannot be the same: both are 'com.
- android环境配置之后,编译时提示:The project cannot be built until build path errors are resolved 的解决方案
- AddFieldAsXml cannot be used to set the InternalName correctly
- Deprecated: Methods with the same name as their class will not be constructors in a future version o
- qt: The build directory needs to be at the same level as the source directory.
- Deprecated: Methods with the same name as their class will not be constructors in a future version
- [PHP] Deprecated: Methods with the same name as their class will not be constructor...
- struts2的“The file cannot be validated as the host "struts.apache.org" is currently unreachable"问题解决
- The project cannot be built until build path errors are resolved解决方案
- Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- Error: member names cannot be the same as their enclosing type
- [未解决] The username entered must be the same as the database accesss account for the server farm you wish to join.
- The project cannot be built until build path errors are resolved 解决方案
- Dapper:The member of type SeoTKD cannot be used as a parameter Value
- as 导入eclipse项目报错:Error:Application and test application id cannot be the same: both are 'com.hjy.act
- Synthesized property 'xx' must either be named the same as a compatible ivar or must explicitly name
- 错误:The project cannot be built until build path errors are resolved 和 Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'MyJavaCode'的解决方法
- The type org.apache.http.NameValuePair cannot be resolved