zoukankan      html  css  js  c++  java
  • Spring整合Struts2

    Spring整合Struts2
    1整合目的:让Spring的IOC容器去管理Struts2的Action,

    2Struts2是web开源框架,Spring要整合Struts2,也就是说要在web应用使用Spring
    ①. 需要额外加入的 jar 包:
    spring-web-4.0.0.RELEASE.jar
    spring-webmvc-4.0.0.RELEASE.jar

    ②. 加入Spring 的配置文件, 和非 WEB 环境没有什么不同

    ③. 需要在 web.xml 文件中加入如下配置:

    <!-- 配置 Spring 配置文件的名称和位置 -->
    <!-- 指定了Spring的配置文件的位置,也就说用contextConfi来向Spring文件 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- 启动 IOC 容器的 ServletContextListener -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    3怎么整合Struts2
    ①. 正常加入 Struts2的jar包和配置文件

    ②. 在 Spring 的 IOC 容器中配置 Struts2 的 Action
    注意: 在 IOC 容器中配置 Struts2 的 Action 时, 需要配置 scope 属性, 其值必须为 prototype

    <bean id="personAction"
    class="com.atguigu.spring.struts2.actions.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

    4整合原理:



  • 相关阅读:
    (转)贝叶斯推理及应用
    (转)zero copy原理
    (转)c指针问题
    (转)c++ new/delete,new[]/delete[]原理解析
    (转)Spring AOP编程原理、Demo
    (转)spring IOC、DI理解
    Django小例子 – 模型数据的模板呈现
    初探Django Admin(一)
    Windows7下搭建Django运行环境
    初探Django线程发送邮件
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4060414.html
Copyright © 2011-2022 走看看