struts1x与spring2.5集成主要步骤

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”,使对象成为多例,这也可以避免单例造成的同步问题。

 

 以上均为个人经验,如有不对请多多指正。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值