Spring整合Struts1.2配置方式

本文介绍两种Spring与Struts1.2整合方案:一是修改struts-config.xml使用DelegatingActionProxy,并配置对应的Spring文件;二是使用DelegatingRequestProcessor及ContextLoaderPlugIn插件实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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的配置,同方案一该部分】

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值