Struts与Spring集成方式
来源:互联网 发布:刚进入金融行业 知乎 编辑:程序博客网 时间:2024/05/01 14:27
struts1.x版本和spring的集成与struts2.0和spring的集成存在较大的差异
struts1.x与spring集成方式
方式一:Action交给spring管理,将业务类注入action
引入spring-webmvc-struts.jar包到lib下,
struts配置:
<action path="/searchAction" type="org.springframework.web.struts.DelegatingActionProxy" parameter="method">
<forward name="success" path="/result.jsp"/>
</action>
spring配置:
<!--这里SearchAction继承了DelegatingActionProxy-->
<bean name="/searchAction" class="com.myproject.action.SearchAction" scope="prototype">
<property name="searchService" ref="searchService"/>
</bean>
注意:保持spring配置的bean name和struts配置的action path一致
方式二:请求首先交给ActionServlet,然后给org.springframework.web.struts.DelegatingRequestProcessor,由这个请求处理器根据请求路径从spring容器获取action对象
struts-config.xml
<action path="/searchAction"> <!--注意到没有?这里没有配置type属性-->
<forward name="success" path="/result.jsp"/>
</action>
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>
spring配置:
<bean name="/searchAction" class="com.myproject.action.SearchAction" scope="prototype">
<property name="searchService" ref="searchService"/>
</bean>
方式三:Action不交给spring管理,直接在Action中实例化应用上下文,然后通过getBean("xxx"),获取相应业务对象
struts配置遵照传统方式
<action path="/searchAction" type="com.myproject.action.SearchAction">
<forward name="success" path="/result.jsp"/>
</action>
private ApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
SearchService searchService=(SearchService)context.getBean("searchService");
struts2.x与spring集成
struts.properties 配置
struts.objectFactory=spring #指定struts的action类实例由spring生成
struts-config.xml配置
<action name="search" class="searchAction" method="searchMax">
<result name="success">/result.jsp</result>
<result name="error">/error.jsp</result>
</action>
spring配置
<bean id="searchAction" class="com.myproject.action.SearchAction" scope="prototype">
<property name="searchService" ref="searchService"/>
</bean>
以上标红的两处须保持一致。
- Struts与Spring集成方式
- Struts与Spring集成方式(一)
- struts与spring集成的另一种方式
- Spring与Struts集成
- Spring与Struts集成
- struts与spring集成
- struts与spring集成
- spring + struts 无缝集成方式
- Struts与Spring的集成
- Spring与Struts的集成
- Spring与Struts集成笔记
- Spring与Struts相集成
- struts与spring集成方案
- 深入探讨Spring与Struts集成方案
- 深入探讨Spring与Struts集成方案
- Spring, Hibernate与Struts集成思路
- Spring, Hibernate与Struts集成思路
- 探讨Spring与Struts 的集成方案
- The C10K problem翻译
- windows 2003,windows 7,windows xp 混装方法
- Effective C++学习3 条款03:尽可能使用const
- 开通博客!
- [转贴]怎样让一个Service开机自动启动
- Struts与Spring集成方式
- 想问前辈一下问题
- 关于 webAppRootKey 发布工程时报错
- 数据库设计2
- ubuntu下编译、运行larbin
- 求正整数中第K个二制中不含11的数
- typedef和#define的区别
- 香葱肉松面包片
- GridView中CheckBox 全选 撤选 的应用