spring和struts的依赖包配置

集成原理:将Struts的Action交给Spring创建,这样业务逻辑对象将会被注入,这样 就避免了依赖查找

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-value>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

3、struts-config.xml文件中<action>标签的Type属性需要更改为Spring的代理Action类org.springframework.web.struts.DelegatingActionProxy
代理Action的作用:取得BeanFactory,然后到IOC容器中将本次请求对应的Action取出

4、将Action交给Spring创建,必须配置业务逻辑对象,注入给Action
<bean name="/login" class="com.tgb.usermgr.web.actions.LoginAction">
<property name="userManager" ref="userManager"/>
</bean>
*必须使用name属性,而且name属性的值必须和struts-config.xml文件中<action>标签的path属性值一致
*必须配置业务逻辑对象
*建议将scope设置为scope="prototype"这样Struts的Action将是线程安全的 但是频繁创建对象

spring和struts的依赖包配置 - 冷月寒 - 冷月寒

转自http://hanzhengyang0126.blog.163.com/blog/static/117503945201151494633531/

你可能感兴趣的:(spring)