spring与struts整合方式二
来源:互联网 发布:tda100软件下载 编辑:程序博客网 时间:2024/06/06 04:55
集成原理:将Struts的Action交给Spring创建,而不是让struts来进行创建.这样业务逻辑对象将会被注入,这样就 避免了依赖查找
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、struts-config.xml文件中<action>标签的type属性需要更改为Spring的代理Action类:org.springframework.web.struts.DelegatingActionProxy
代理Action的作用:取得BeanFactory,仍然是从ServletContext里面取得这个BeanFactory的,然后到IoC容器中将本次请求对应的Action取出
4、将Action交给Spring创建,必须配置业务逻辑对象,注入给Action
<bean name="/login" class="com.bjpowernode.usermgr.web.actions.LoginAction">
<property name="userManager" ref="userManager"/>
</bean>
* 在contextApplication.xml中必须使用name属性,为什么要用name属性?id不能定位特殊字符的.而且name属性的值必须和struts-config.xml文件中<action>标签的path属性值一致
* 必须配置业务逻辑对象
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、struts-config.xml文件中<action>标签的type属性需要更改为Spring的代理Action类:org.springframework.web.struts.DelegatingActionProxy
代理Action的作用:取得BeanFactory,仍然是从ServletContext里面取得这个BeanFactory的,然后到IoC容器中将本次请求对应的Action取出
4、将Action交给Spring创建,必须配置业务逻辑对象,注入给Action
<bean name="/login" class="com.bjpowernode.usermgr.web.actions.LoginAction">
<property name="userManager" ref="userManager"/>
</bean>
* 在contextApplication.xml中必须使用name属性,为什么要用name属性?id不能定位特殊字符的.而且name属性的值必须和struts-config.xml文件中<action>标签的path属性值一致
* 必须配置业务逻辑对象
* 建议将scope设置为prototype,这样struts的Action将是线程安全的,每次请求都创建一个Action,图示.
- spring与struts整合方式二
- struts 与 spring 的整合方式
- spring与struts的整合方式一
- struts 与spring整合两种方式
- spring+struts整合方式
- struts spring 整合方式
- mybatis与spring整合(方式二)
- 整合Struts 与Spring
- 整合Struts 与Spring
- 整合Struts 与Spring
- struts与spring整合
- spring与struts整合
- Spring与Struts整合
- Spring与Struts整合
- Spring与struts整合
- Spring与Struts整合
- spring 与struts 整合
- struts与spring整合
- 基于用户管理的备份与恢复
- spring与jdbc的整合
- 心情随笔
- spring与struts的整合方式一
- 集训概况
- spring与struts整合方式二
- 研发素质模型
- 每个.Net开发者现在应该下载的十个必备工具!
- Linux的一些基本概念
- 阻塞队列问题
- FreeType Glyph Conventions
- C++虚函数表解析(转)
- 公安派出所人口管理系统 3.0 FLEX版
- ASP.NET生命周期