spring整合struts2
使spring IOC容器来管理Struts2的Action
首先加入struts2和spring需要的jar包,然后在加入struts-spring-plugin的jar文件。
在src路径下创建spring的核心配置文件applicationContext.xml和struts的核心配置文件struts.xml
最后在web.xml文件中加入下列代码:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:在struts的核心配置文件中声明action的时候,class为spring的配置文件中的bean的id值
希望可以帮助各位小伙伴,如有不足之处,请提出指正,谢谢!!!

浙公网安备 33010602011771号