spring与struts的整合方式一

集成原理:在Action中取得BeanFactory,通过BeanFactory取得业务逻辑对象

1、spring和struts的依赖包配置
* struts
--拷贝struts和jstl的依赖包
--在web.xml文件中配置ActionServlet
--提供struts-config.xml文件
--提供国际化支持,提供缺省的国际化资源文件
* spring 
--拷贝spring相关依赖包
--提供spring的配置文件


2、在web.xml文件中配置ContextLoaderListener,让Web Server在启动的时候将BeanFactory放到ServletContext中
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext-*.xml</param-value>
  </context-param>
  
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
3、在Action中采用 WebApplicationContextUtils.getRequiredWebApplicationContext()从ServletContext中取得BeanFactory,WebApplicationContextUtils是spring提供的工具包
   
4、通过BeanFactory从IoC容器中取得业务逻辑对象


存在缺点:
因为Action中出现了依赖查找,所以Action依赖Spring的API

进一步了解依赖查找和依赖注入    

图示:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yjsuge

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值