一、在web.xml中配置Spring容器的启动 (通用的方法)
<
context-param
>
< param-name > contextConfigLocation </ param-name >
< param-value > /WEB-INF/classes/applicationContext.xml </ param-value >
//如有多个spring配置文件用逗号隔开
</ context-param >
<!-- 通过Listener配置Spring容器随Web应用的启动而初始化 -->
< listener >
< listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
</ listener >
< param-name > contextConfigLocation </ param-name >
< param-value > /WEB-INF/classes/applicationContext.xml </ param-value >
//如有多个spring配置文件用逗号隔开
</ context-param >
<!-- 通过Listener配置Spring容器随Web应用的启动而初始化 -->
< listener >
< listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
</ listener >
二、struts1的启动方法
<
plug-in
className
="org.springframework.web.struts.ContextLoaderPlugIn"
>
< set-property property ="contextConfigLocation" value ="/WEB-INF/applicationContext.xml,
/WEB-INF/action-servlet.xml" />
</ plug-in >
< set-property property ="contextConfigLocation" value ="/WEB-INF/applicationContext.xml,
/WEB-INF/action-servlet.xml" />
</ plug-in >
补充: 让spring中配置bean接管struts1的Action的, 要在struts-config.xml中加入
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
好像这个配置只能放在Action-mapping后面
struts2就不用这么麻烦了,用第一种方法启动Spring容器,然后建立与Struts2中的Action名字相同的Bean即可