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



  • 相关阅读:
    SVM高斯核为何会将特征映射到无穷维?【转载】
    sklearn.svm.LinearSVC文档学习
    NgDL:第四周深层神经网络
    Py中的矩阵乘法【转载】
    NN中BP推导及w不能初始化为0
    L2-006 树的遍历
    P3144 关闭农场 并查集 反向
    P1197 [JSOI2008]星球大战 并查集 反向
    P2700 逐个击破 最小生成树
    L2-005 集合相似度
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4060414.html
Copyright © 2020-2023  润新知