struts2.3.3整合spring3.3.1

来源:互联网 发布:toastr.js 编辑:程序博客网 时间:2024/05/01 05:19


struts2.3.3整合spring3.1.1


一、整合jar

(1)添加struts2插件jar  struts2-spring-plugin-2.1.6.jar

(2)添加struts2jar

(3)添加springjar

(4)去掉重复及缺少的部份commons jar

         整合完毕后jar包截图为:

 

 

二、在src下创建applicationContext.xml(即:beans.xml)struts.xml


三、配置web.xml

(1)配置spring监听器及配置文件加载路径

 <!-- 通过监听器监听spring,当服务器一启动时spring就进行加载 -->   <context-param>    <param-name>contextConfigLocation</param-name>      <param-value>classpath:applicationContext.xml</param-value></context-param>   <!-- 如果有多个文件,并且是放在WEB-INF可通过如下写法   <context-param>    <param-name>contextConfigLocation</param-name>     <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value></context-param> --><listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

(2)配置struts2filter  

    

<!-- 配置struts2的filter --><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter>

四、applicationContext.xml配置各bean之间的依赖关系

 <bean id="loginAction"  class="com.cms.admin.action.LoginAction" scope="prototype">   <property name="loginServicesImpl" ref="loginServicesImpl"></property>   </bean> <bean id="loginServicesImpl"  class="com.cms.admin.services.impl.LoginServicesImpl" ></bean>

五、配置struts.xml

  <package name="login" namespace="/" extends="struts-default">        <action name="loginAction"  class="loginAction">            <result  name="success">/success.jsp</result>             <result  name="fail">/fail.jsp</result>        </action>    </package>

注:上图的class,并不是action的实际类,而是在applicationContext.xml里配置的bean的 id名子。


源码可以通过如下地址来下载:

"http://115.com/file/dpgfhudq#struts2_spring.rar


在后期的开发中发现一个版本的问题:在上面提供的包中,发现高版本的hibernate的jar 已经和annotation的合并了,所以要去掉 hibernate-commons-annotations.jar

和hibernate-annotations.jar;asm-3.3.jar和spring自代的asm包也有冲突,所以这个包也要去掉。




原创粉丝点击