Spring集成 Struts2

Spring与Struts2整合实践
本文介绍如何使用Spring框架整合Struts2,实现由Spring IOC容器管理Struts2的Action。具体步骤包括配置Spring管理的Action、设置正确的scope属性为prototype、配置Struts2的action节点指向Spring管理的bean及引入插件jar。

Spring如何整合struts2?
  1) 整合目标?

    使IOC容器来管理Struts2的Action!

  2) 如何进行整合?

         ① 正常加入Struts2
         ② 在Spring的IOC容器中配置Struts2的Action
   特别注意:在IOC容器中配置Struts2的Action时,需要配置scope属性,且必须指定为prototype!

<bean id="personAction" class="com.lty.spring.struts2.action.PersonAction" scope="prototype">
       <property name="personService" ref="personService"></property>
</bean>

         ③ 配置Struts2的配置文件:action节点的class属性需要指向IOC容器中该bean的id

<action name="person-save" class="personAction">
    <result>/success.jsp</result>
</action>

        ④ 加入struts2-spring-plugin-2.3.15.3.jar

     3)整合原理

         通过添加struts2-spring-plugin-2.3.15.3.jar以后,Struts2会先从IOC容器中获取Action的实例

if (appContext.containsBean(beanName)) {
    o = appContext.getBean(beanName);
} else {
    Class beanClazz = getClassInstance(beanName);
    o = buildBean(beanClazz, extraContext);
}

 

转载于:https://my.oschina.net/Howard2016/blog/1564385

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值