Spring整合Struts1.2配置方式

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" /> </plug-in>


 其实Spring整合Struts1.2就是想办法让Action加载的时候能从Spring中获得,这样就解决了Action中Service的依赖注入问题了,也就解决了所有问题了。

按照这种思路,我们可以找到两种解决方案:

第一种配置方案(不推荐的):

【修改struts-config.xml文件需要添加下面插件(注意包是否在项目中)】

 

【所有action的type改成】
org.springframework.web.struts.DelegatingActionProxy

【配置对应的Spring文件/WEB-INF/applicationContext.xml,添加对应的action的bean设置】

(在spring1.2下)
 

<bean name="/user" class="com.mycom.struts.action.UserAction" singleton="false"> <property name="xxxService"> <ref bean="XxxService" /> </property> </bean>

 
----------------------------------------
(在spring2.0下)
 

<bean name="/user" class="com.mycom.struts.action.UserAction" scope="prototype" > <property name="xxxService"> <ref bean="XxxService" /> </property> </bean>

 

(两个版本下的非单例模式配置不同)
=======================================================================

第二种配置方案(推荐的):

(注意顺序:controller,message-resources,plug-in)

 

【配置struts-config.xml文件,添加】

<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" /> </plug-in>

 

 【Spring中添加对应Action的配置,同方案一该部分】

 

你可能感兴趣的:(spring,bean,xml,Web,struts)