struts2.3.3整合spring3.3.1


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包也有衝突,所以這個包也要去掉。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章