一、原因:
问题处在你导入的“Struts2 Spring Libraries”库下的“Struts2-spring-plugin-2.2.1.jar”jar包下的struts-plugin.xml里。如下图:
问题出现的具体位置在上图所示的第29行的代码,这段代码如下:
<bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
这 表明该插件引入工程后,会自动设置Struts的 ObjectFactory为 StrutsSpringObjectFactory,从而让Spring的IOC容器来托管Struts的Action。但是 在工程的web.xml中 没有配置 加载spring ApplicationContext相关的listener ,从而导致了启动时出现的问题:com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1。
二、解决办法
在工程的web.xml中 配置 加载spring ApplicationContext相关的listener ,配置的代码如下:
<context-param><param-name>
contextConfigLocation
</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>