1.导入struts和spring(spring的jar包,common-logging的jar包及log4j.properties)的jar包
2.复制applicationContext-*.xml配置文件到src即classpath能找到的路径或web-inf下
3.配置web.xml文件,加入如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml,/WEB-INF/applicationContext-*.xml</param-value>
</context-param>
其中,classpath*:applicationContext-*.xml是指找到classpath路径下的配置文件,注意一定要用*:,WEB-INF同理,多个路径之间用逗号或者空格隔开,这意思即为通过contextConfigLocation读取spring的配置文件。此外还需要配置一个监听,此监听的目的就是为了读取到contextConfigLocation,使其能成功加载spring配置文件,配置如下:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
4.配置struts配置文件,action标签中别的不变,将原来的请求控制交给spring处理,即将type改为:
type="org.springframework.web.struts.DelegatingActionProxy"
若找不到此类,则找到spring jar包里面的spring-webmvc-struts.jar,复制到lib包下
5.修改spring配置文件,传统的配置方法是<bean id=”” class=”” />,如果将struts与spring结合,需要将spring的id改为name,些name必须唯一,后面还能跟scope=”prototype”,使对象成为多例,这也可以避免单例造成的同步问题。
以上均为个人经验,如有不对请多多指正。