Spring集成 Struts2

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

    使IOC容器來管理Struts2的Action!java

  2) 如何進行整合?

         ① 正常加入Struts2
         ② 在Spring的IOC容器中配置Struts2的Action
   特別注意:在IOC容器中配置Struts2的Action時,須要配置scope屬性,且必須指定爲prototype!spring

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

         ③ 配置Struts2的配置文件:action節點的class屬性須要指向IOC容器中該bean的idapp

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

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

     3)整合原理

         經過添加struts2-spring-plugin-2.3.15.3.jar之後,Struts2會先從IOC容器中獲取Action的實例ui

if (appContext.containsBean(beanName)) {
    o = appContext.getBean(beanName);
} else {
    Class beanClazz = getClassInstance(beanName);
    o = buildBean(beanClazz, extraContext);
}
相關文章
相關標籤/搜索