Spring整合Struts
来源:互联网 发布:vb与c#语法区别 编辑:程序博客网 时间:2024/06/05 05:17
Spring整合Struts
为什么整合?
使用Spring的IOC功能将业务类注入Action
由Spring创建并管理Action
Spring容器通过Web容器启动(配置监听器ContextLoaderListener即可完成)
步骤:
1、如何启动Spring容器?
配置监听器ContextLoaderListener即可完成,在web.xml中配置
<context-param>
<param-name>contextConfigLocation</param-name><!-- 固定的 -->
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置监听器启动Spring容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2、将创建Action的工作委托给Spring完成,该工作由Spring提供的代理类DelegatingActionProxy实现。
applicationContext.xml:
<!-- name的值必须是Action的path属性值 -->
<bean name="/test" class="com.aptech.struts.action.TestAction"></bean>
struts-config.xml:
<action path="/test" type="org.springframework.web.struts.DelegatingActionProxy" />
3、将业务对象注入到Action
4、为了能够在Action中访问WEB对象,如ServletContext,则必须将Action配置在单独的文件中,并通过Struts插件(ContextLoaderPlugIn)来加载该文件。
struts-config.xml:
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="classpath:action-beans.xml" />
</plug-in>
得到ServletContext里的spring对象有如下方法:
ServletContext servletContext = this.getServlet().getServletContext();
方法一:
{
XmlWebApplicationContext xmlWebApplicationContext = (XmlWebApplicationContext) servletContext
.getAttribute(WebApplicationContext
.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
}
方法二:
{
WebApplicationContext xmlWebApplicationContext =
WebApplicationContextUtils
.getWebApplicationContext(servletContext);
System.out.println(xmlWebApplicationContext);
}
- struts整合spring整合hibernate
- 整合 struts spring hibernate
- Spring , Struts整合方法
- 整合Struts 与Spring
- 整合Struts 与Spring
- struts整合spring
- struts+spring+hibernate整合
- struts,hibernate,spring整合
- 整合 Struts 和 Spring
- struts+spring+hibernate整合
- struts+spring+hibernate整合
- struts+spring整合测试
- 整合Struts 与Spring
- struts和spring整合
- struts+spring整合测试
- 整合 Struts 和 Spring
- struts+spring整合
- struts与spring整合
- 【算法-排序之五】选择排序
- MySQL查看并修改当前数据库编码
- Spring整合Hibernate的步骤
- 操作系统的 输入-分发-处理-输出
- OpenStack Object Storage(Swift)
- Spring整合Struts
- 单链表排序(快速排序、归并排序)
- 马云的来往软着陆
- 根据属性操作JSON对象
- 链表中递归查找元素,非递归查找元素 以及基数排序(未完成)josephus问题(未完成)
- 腾讯2013年实习生笔试题目
- 今天看到的一个有趣面试题:return *this和return this有什么区别?
- usaco-1.2.5 Palindromic Squares
- HDU 2091 空心三角形