一、需要的JAR文件为:Spring和Struts2框架本身需要的JAR文件以及他们所依赖的JAR文件

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARoAAAFnCAIAAAD2bRHyAAAenElEQVR4nO2d7a8c1X3H7x/Qd33XF31V8aIQRRFVQ1aqWll9IoqSqlKRrRYitWibF6hqCaQ1LiSlxg8oJgt+oJILSaBAAgYbijcV1LEINhQCERBMnayfrm18fe29+IJ9YeMabV/szsx5+P3OObP7m4cz+/3oyvKdPXPm7N357pyZnd9n54YV023PtbvD4bDXac21Or3x/9rdqscFQH7mRHr5eOnU69tvOnDvlw/c++XXt9/08dKp4FURJ9AcZOL00r1f+aTf+/ST859+cv7Dk2++uu2m4FWTOGUgTiBWguK0f//+TZs2cY9+3D/+8j2fP3Nw3YV3Nlx8Z/3yG98889+3v73zL3669Us/3fqlt7771V9d6vN9I06gOfjjtG/fvquvvvqqq67iGryy5Y/PvrVz+eiTHx3f9dHxXR8de2q59+SF3g8/PL7nw+N7+u89+vr2P+e7Vyd7oxCN/tdtz41BtEAseOI0ytLq1asdcXrxrmsHi13Hz4t3XctvgY5TFqJuG4ECseCKU5qlNWvWOOL0o3WfG5x+avSzcvyx3o/+4fV//7OX71/18v2rXu6sermz6sebvnDggesPPHD9gQe+aK3NHZ3SBpj7gWhg46RmyR2n5/7xs4MT3xuc+N4Hb3/n4I7rF392/2Dh2cHCc4OF5wZn/3Nw9vnB2b2Dxe4Hhx/Zt/kPrLURJ9Ac2Dht2rTpKoUNGzZwLZ/5+mcGR7YvvXHP/i2rlt76zmD+kcH8I4P5Rwcn/2Nw8rHByccHp55YemfbC/f+Uf/4z6y1mcleEiDtFwDqjcCF8h/+/TX9V9e9uOn3+6/fPehtHfS2DnrbBke2D47sGBx5cHD03/pvbOzes+r8sTeptZmjUxtXIkB8CMTpsVt+e+83P3/+4O2DQ/86OLR+cOiewXsbBu9tHLy3afC/m88dvOP59X947iiZJQAahUCc3ty95dFbrn7yts899Y3f2fVPv/v02uueWXvdM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qVMW36UIYlvZuzv5rOnOc8VpGo+F0gd16WVO23hsHgu4ImQp4MULnezJdh4PpebFA1wRsoi8tspsyXUyP9m2AjuPBu/VxzKBK0IWobdKZbbE7yqTbiuo8xion8cCrggAxED5IABiIE4AiIE4ASAG4gSAGHBFACAGXBEAiAFXhEqdPmCvnFp9PhoJcEWo1CBO0zgYXOu6boCg78xDnPLTJFfE9FQep2kcDK51tcqTofVA7LdH1IYmuSKmp/I4qeR1MPAPJ7eeW2uMD0ANuA+2JsTqilBrfUbvxco+obw5E6Wsdt1EKhLQKqD4mmh7UhXSObkiz6QOBmvd8ZMK1jYkmOVjRMVFaQ6GWIjWFZHuBMm+oBbstFpZIV5azZS96KxIIOnDdaJhPxbYuVFH5DwMapWB5nLPXZ/6uulwpohT9Q6GWIjXFTE0VQ1ZFlqd3uhEgikX52rOs4I8dS/RNQn2rhfYuVVyp1ctyjgYzHX1Q/bkRyfi+FSriXFdiNoVYZhPRuFRgtTtGAephPRSFhGnuVbLdUUrKE5U52EnKNM4GJgLEESI/X0NjbeFih0MsRCtKyLZCdTLub1Oq9XK9oF0ykfMx6y9Y6j+ys21kq6Sh7odciZJd67t7d021f00Dgbf7q2PKzIHQyzE6opQdmHjJVavJag7jeNqQdpG/XXUntvpjX5COidP6O1npZHDweCTW0wepxo4GGIBrgjAgLzkB64IQIObIiYArghgUT8HQyzAFQGAGCgfBEAMxAkAMRAnAMRAnAAQA3ECQIz/B+/uZnXw8wMYAAAAAElFTkSuQmCC" alt="" />

二、在web.xml中增加WebApplicationContext的相应配置,以下两种配置方式本质是一样的。
1.  Servlet 2.3及以上版本可以使用监听器,相应配置如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
如果spring配置文件被命名为applicationContext.xml,并且放在WEB-INF目录下,则不需要配置<context-param>,因为ContextLoaderListener默认在WEB-INF目录下寻找名为applicationContext.xml的文件。若存在多个Spring配置文件,则在<param-value>中依次列出,之间以逗号隔开。
2. Servlet 2.3以下版本由于不支持<listener>,需要配置<servlet>,格式如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>contextLoaderServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
如果spring配置文件被命名为applicationContext.xml,并且放在WEB-INF目录下,则不需要配置<context-param>,因为ContextLoaderListener默认在WEB-INF目录下寻找名为applicationContext.xml的文件,或者是名字为contextConfigLocation的ServletContext参数所指定的文件。由于该Servlet配置只是为了在容器启动时能启动ContextLoaderServlet使其工作,而不需要引用该Servlet,所以不需要配置<servlet-mapping>
三,配置struts.xml,如下示例
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- struts.enable.DynamicMethodInvocation = true,-动态方法调用,为true时,就可以在struts.xml配置“*”的通配符,来调用action里的方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 是否启用开发模式 -->
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value=",do" />
<!-- 指定由spring负责action对象的创建 -->
<constant name="struts.objectFactory" value="spring" />
<!-- struts配置文件改动后,是否重新加载 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 设置浏览器是否缓存静态内容 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 该 default package中放置一些公共配置 -->
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/WEB-INF/pages/public/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>
</package>
<!-- 该 strutsAction package中放置action配置 -->
<package name="strutsAction" namespace="/" extends="default">
<action name="index">
<result>index.jsp</result>
</action>
<action name="helloStrutsAction_*" class="com.vrv.paw.action.HelloStrutsAction" method="{1}">
<result name="{1}">/WEB-INF/pages/helloStrutsAction/{1}.jsp</result>
</action>
</package>
</struts>
四,在web.xml中完成加载WebApplicationContext之后,接下来就可以做到Spring和Struts2的整合了。整合有两种方法,分别叙述如下:
1. 第一种实现方法:(1) 将Struts的业务逻辑控制器类配置在Spring的配置文件,[一般是application.xml]中,业务逻辑控制器中引用的业务类一并注入。
    注意,必须将业务逻辑控制器类配置为scope=”prototype”
示例如下:
<bean id=”LoginAction” class=”yaso.struts.action.LoginAction”>
<property name=”loginDao” ref=”LoginDao”/>
</bean>
           (2)在struts.xml或者等效的Struts2配置文件中配置Action时,指定<action>的class属性为Spring配置文件中相应bean的id或者name值。示例如下:
<action name=”LoginAction” class=”LoginAction”>
<result name=”success”>/index.jsp</result>
</action>
2. 第二种实现方法:(1)业务类在Spring配置文件中配置,业务逻辑控制器类不需要配置,Struts2的Action像没有整合Spring之前一样配置,<action>的class属性指定业务逻辑控 制器类的全限定名。
             (2)业务逻辑控制器类中引用的业务类不需要自己去初始化,Struts2的Spring插件会使用bean的自动装配将业务类注入进来,其实业务逻辑控制器也不是Struts2创建的,而是Struts2的Spring插件创建的。默认情况下,插件使用by name的方式装配,可以通过增加Struts2常量来修改匹配方式:设置方法为:struts.objectFactory.spring.autoWire = typeName,可选的装配参数如下:
  a)         name:等价于Spring配置中的autowire=”byName”,这是缺省值。
  b)        type:等价于Spring配置中的autowire=”byType”。
  c)         auto:等价于Spring配置中的autowire=”autodetect”。
  d)        constructor:等价于Spring配置中的autowire=” constructor”
 
 
 
如果原先在Struts2中使用了多个object factory,则需要通过Struts2常量显式指定object factory,方式如下:struts.objectFactory = spring;如果没有使用多个object factory,这一步可以省略。
可以通过设增加Struts2常量来指定是否使用Spring自身的类缓存机制。可以设定的值为true或false,默认为true。设置方式为:struts.objectFactory.spring.useClassCache = false。

至此,完成了两种方式的整合。比较这两种整合方式,其本质是一样的。不同之处在于,使用第二种自动装配的方式时,由于没有在Spring中配置业务逻辑控制器,所以需要对其配置一些AOP之类的内容时就很难实现了

 
 

整合Struts2与Spring的更多相关文章

  1. 基于注解整合struts2与spring的时候如果不引入struts2-spring-plugin包自动装配无效

    基于注解整合struts2与spring的时候如果不引入struts2-spring-plugin包,自动装配将无效,需要spring注入的对象使用时将抛出空指针异常(NullPointerExcep ...

  2. cpj-swagger分别整合struts2、spring mvc、servlet

    cpj-swagger 原文地址:https://github.com/3cpj/swagger 1. Swagger是什么? 官方说法:Swagger是一个规范和完整的框架,用于生成.描述.调用和可 ...

  3. 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...

  4. 整合Struts2+SiteMesh+Spring+MyFaces(JSF)+Freemarker的时候启动服务器报错ClassNotFoundException: org.apache.struts2.sitemesh.FreeMarkerPageFilter

    我一琢磨,难道freemarker与struts2的整合也需要添加一个struts2-freemarker-plugin的jar包? 后来找了半天,确认不需要这个. 然后我就上网搜,这个FreeMar ...

  5. 重新学习之spring第四个程序,整合struts2+hibernate+spring

    第一步:导入三大框架的jar包(struts2.3.16.1+hibernate3.2+spring3.2.4) 第二步:编写web.xml 和struts.xml和applicationContex ...

  6. web项目中加入struts2、spring的支持,并整合两者

    Web项目中加入struts2 的支持 在lib下加入strut2的jar包 2. 在web.xml中添加配置 <filter> <filter-name>struts2< ...

  7. Spring第四篇【Intellij idea环境下、Struts2和Spring整合】

    前言 Spring的第二和第三篇已经讲解了Spring的基本要点了[也就是Core模块]-本博文主要讲解Spring怎么与Struts2框架整合- Struts2和Spring的整合关键点: acti ...

  8. Struts2与Spring整合

    前言 本博文主要讲解Spring怎么与Struts2框架整合... Struts2和Spring的整合关键点: action对象交给Spring来创建 搭建环境 进入jar包 引入jar文件: 1)引 ...

  9. struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决

    最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myec ...

随机推荐

  1. oracle 数据库误删数据,误删表的恢复

    1.某表的数据误删了,那么可以查询这个表某一时间节点之前的数据,并放到一个新建的表里. create table temptable as select * from t_billdefi  as O ...

  2. javascript面向对象笔记(一)

    ECMAscript对象(以下简称对象): ECMA-262把对象定义为:无序属性的集合,其属性可以包含基本值.对象或者函数. 对象的每个属性或方法都有一个名字,而每个名字都映射到一个值.值可以是数据 ...

  3. 002-jdk10安装

    下载地址: 1.百度云下载地址.(当然也可以官网下载,都一样) 地址:https://pan.baidu.com/s/13oZh_5tXb_Xadg9f-y2Idw 密码:a9h8 安装jdk: 2. ...

  4. 安装java项目开发环境

    搭建java 查看本机是否已有java 如果有,请卸载. 下载jdk 复制到服务器中 临时配置你在shell里面改,只是做了临时更改啊,一重启就没了 配置到系统的环境变量里 export JAVA_H ...

  5. TOSCA自动化测试工具--怎么写自动化用例

    1.查看一下要测试的对象属性 2.

  6. “凯易迅Calix”实习上机——打折问题

    题目要求: 题目记得不太清楚,大概的意思是一个商店的打折方案如下:设一个客户买了n个商品,价格分别是p1,p2,...,pn (1)第一个商品不打折,即cost=p1; (2)第i个商品的折扣d=mi ...

  7. 手写Bind

    Function.prototype.bind2 = function(context){ var self = this; var args = [].slice.call(arguments,1) ...

  8. C++之map使用

    解析文件或者字符串,一key跟keyvalue来存在map中,如下代码: test.h: #include <map>#include <vector> Class test ...

  9. linux lanmp一件安装包

    转载地址:http://lamp.phpstudy.net/ phpStudy Linux版&Win版同步上线 支持Apache/Nginx/Tengine/Lighttpd/IIS7/8/6 ...

  10. web.xml<context-param>与<init-param>的作用与区别

    <context-param>的作用:web.xml的配置中<context-param>配置作用1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件we ...