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



  • 相关阅读:
    #454. 【UER #8】打雪仗
    6496. 【GDOI2020模拟03.08】圣痕
    6495. 【GDOI2020模拟03.08】死星
    6494. 【GDOI2020模拟03.08】勘探
    NOI Online划水记
    6482. 【GDOI2020模拟02.22】代数几何(algebraic)
    6493. 【GDOI2020模拟03.04】迷宫
    6492. 【GDOI2020模拟03.04】多项式
    6491. 【GDOI2020模拟03.04】铺路
    #76. 【UR #6】懒癌
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4060414.html
Copyright © 2011-2022 走看看