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



  • 相关阅读:
    [HAOI2008]硬币购物
    [SCOI2005]骑士精神
    [ZJOI2007]最大半联通子图
    [HAOI2007]反素数
    [SCOI2005]繁忙的都市
    小凯的疑惑
    5月16日vj题解
    周六题目前四题详解
    Codeforces Round #629 (Div. 3)做题记录
    Codeforces Round #570 (Div. 3) B. Equalize Prices
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4060414.html
Copyright © 2011-2022 走看看