日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring与Struts2整合的两种解决方案

發布時間:2024/4/17 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring与Struts2整合的两种解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://www.itzhai.com/spring-and-struts2-integration-of-the-two-solutions.html

Struts2與Spring整合的方案一: (1)將struts2-spring-plugin-x-x-x.jar復制到工程的WEB-INF/lib目錄下,在該插件包中有個struts-plugin.xml文件,該文件的默認配置如下: <struts><bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" /><!-- Make the Spring object factory the automatic default --><constant name="struts.objectFactory" value="spring" /><package name="spring-default"><interceptors><interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/><interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/></interceptors></package> </struts> (2)在web.xml中配置Spring的監聽器: <context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext-*.xml</param-value> </context-param> <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> (3)修改Struts.xml配置文件:

在配置Action時,需要將class屬性和Spring配置文件中的相對應的Action的bean的Id的屬性保持一致,系統即可通過Spring來裝配和管理Action。
如果action包含了Service層的對象:

private StudentInfoServiceImpl studentInfoService;

則需要添加set方法,才可以使用Spring依賴注入:

public void setStudentInfoService(StudentInfoServiceImpl studentInfoService) {this.studentInfoService = studentInfoService; } 如果action在struts.xml如下配置: <action name="studentRegister" class="studentRegisterAction"><result name="result">/WEB-INF/exam/result.jsp</result><result name="input">/WEB-INF/exam/error.jsp</result><interceptor-ref name="excludeParamsStack" /> </action> 則在applicationContext.xml文件中該Action的配置如下: <bean id="studentRegisterAction" class="com.exam.actions.StudentRegisterAction" scope="prototype"><property name="studentInfoService"><ref bean="studentInfoService" /></property> </bean> Struts2與Spring整合的方案二:

前面兩個步驟和方案一的一樣;
在配置struts.xml文件時,Action的class為該Action的類路徑,而在applicationContext.xml配置文件中不需要添加Action的bean配置。這樣,當我們使用Action類時,由于studentInfoService已經配置了相關的bean,所以會自動裝配。

studentInfoService的配置: <bean id="studentInfoService" class="com.exam.service.StudentInfoServiceImpl"><constructor-arg><ref bean="studentInfoDAO" /></constructor-arg> </bean> Action在struts.xml中的配置如下: <action name="studentRegister" class="com.exam.actions.StudentRegisterAction"><result name="result">/WEB-INF/exam/result.jsp</result><result name="input">/WEB-INF/exam/error.jsp</result><interceptor-ref name="excludeParamsStack" /> </action>

總結

以上是生活随笔為你收集整理的Spring与Struts2整合的两种解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。