Spring整合Struts1.2配置方式

本文介绍如何通过两种配置方案实现Spring与Struts1.2的整合,解决Action依赖注入问题。第一种方案直接修改Struts配置并使用DelegatingActionProxy;第二种方案推荐使用DelegatingRequestProcessor及ContextLoaderPlugIn。

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

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

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

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

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

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

 

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

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

(在spring1.2下)
 

Code:
  1. <bean name="/user" class="com.mycom.struts.action.UserAction" singleton="false">  
  2.  <property name="xxxService">  
  3.   <ref bean="XxxService" />  
  4.  </property>    
  5. </bean>  


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

Code:
  1. <bean name="/user" class="com.mycom.struts.action.UserAction" scope="prototype" >  
  2.  <property name="xxxService">  
  3.   <ref bean="XxxService" />  
  4.  </property>    
  5. </bean>  

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

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

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

 

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

Code:
  1. <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>     
  2.   
  3. <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">  
  4.   <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />  
  5. </plug-in>  

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

更多文章见:http://www.ruanjianpeixun.net/

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值