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整合原理:



  • 相关阅读:
    诸暨集训游记
    P2678 跳石头
    P1577 切绳子
    P1328 生活大爆炸版石头剪刀布
    P1067 多项式输出
    分解因数
    【管理篇】团队组织与架构演进方法论
    【状态机】行为状体机和协议状态机
    【数据库】分库分表
    【OLAP】从数仓到Kappa架构
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4060414.html
Copyright © 2011-2022 走看看