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>
以上标红的两处须保持一致。
分享到:
相关推荐
struts2入门教程及struts2集成spring。
struts2.2.3集成spring时需要添加的jar包,struts2-spring-plugin-2.2.3.jar
struts2 spring hibernate集成 介绍上传下载。。
flex与+struts2+hibernate+spring集成实例项目,源码奉献,物有所值
struts spring集成 struts spring集成 struts spring集成
struts+spring 集成
struts2 hibernate spring 集成
struts1.x+spring+jta集成例子(包含所有jar包),mysql数据库,表需要自己创建
Struts2的总结和Strut2集成Spring
struts 2应用只需要下列几个必须的jar: commons-logging-1.0.4.jar freemarker-2.3.8.jar ognl-2.6.11.jar ...同时提供struts2为了集成到spring时必须的插件 struts2-spring-plugin-2.0.11.jar
struts1.2 spring2 ibatis 集成项目实战源码
SSH(struts2,Hibernate,Spring)整合及测试亲测可用,百分之白亲测可用。
三大框架集成及两两集成的jar包,spring集成hibernate的jar包以及spring集成struts2的jar包已经单独打包
SSH集成 Struts+spring+hibernate集成SSH集成 Struts+spring+hibernate集成
spring整合struts2与hibernate核心配置文件
struts2+hibernate+spring集成的增删改查例子 非常简单,方便新手教学
通过简单了实例 并提供代码 指导初学者学会spring和struts2的集成 并实现简单的登录功能
struts spring集成原理 struts spring集成原理 struts spring集成原理
flex与 struts2与 hibernate与spring集成实例项目
《Struts Hibernate Spring集成开发宝典》以Struts,Hibernate,Spring为核心详细地讲解了这三个组件的基础知识和基本使用方法,并通过一系列集成开发实例讲解了这三个组件在J2EE项目中的应用。《Struts Hibernate ...