今天在整合spring+struts时,把struts2的配置文件放到src/config/struts/struts.xml,,启动项目老是报错!web下struts拦截器配置如下:
<!– 定义Struts2的核心Filter –><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class><init-param> <param-name>config</param-name><param-value>config/struts/struts.xml</param-value> </init-param></filter><!– 让Struts2的核心Filter拦截所有请求 –><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
运行时老是出错,整了一天才整出来。eclipse错误如下:
com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory,] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory).at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:86)at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:67)at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)at java.util.concurrent.FutureTask.run(FutureTask.java:262)at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:483)at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:523)
可能是应为无法struts-default.xml而报错!
修改方案有两种:
方案1、在struts2.xml中添加一下内容:
<include file="struts-default.xml" />
方案2、修改struts拦截器在web下的配置,如下:
<!– 定义Struts2的核心Filter –><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class><init-param> <param-name>config</param-name><param-value>struts-default.xml,config/struts/struts.xml</param-value> </init-param></filter><!– 让Struts2的核心Filter拦截所有请求 –><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
泪,一种痛苦的雨滴,不知从什么时候开始已在我的世界下个不停。