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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

struts+spring的配置方式总结

發布時間:2025/7/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 struts+spring的配置方式总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

現在最流行的j2ee的程序,一般都是用struts+spring+hibernate框架做的,spring+hibernate的配置方式很簡單,這里就不說了,下面對struts+spring的幾種配置方式做個總結,

第一種方式
1.創建BaseAction類,它繼承Action類,以后所有action類都繼承BaseAction這個類。
?? 比如:public class BaseAction extends Action {
???????????????? ?private ApplicationContext applicationContext;
??????????????? ?//private Service1 service1;
?????????????? ? //private Service2 service2;
??????????????? ?public ApplicationContext getApplicationContext() {
??????????????? ?return applicationContext;
???????????? ?}
2.在web.xml中加入
? <listener>
? ?<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
? </listener>
----------------------------------------------------------------------------------------------
第二種方式
1.所有action類都繼承ActionSupport類
2.在web.xml中加入
? <listener>
? ?<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
? </listener>
----------------------------------------------------------------------------------------------
第三種方式
1.在struts-config.xml中的所有action的type里寫org.springframework.web.struts.DelegatingActionProxy
? 而不寫action的類路徑位置
2.在struts-config.xml中加入
? <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
? ?<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
? </plug-in>?
3.applicationContext.xml中加入
? <bean name="/struts-config.xml中的action" class="struts-config.xml中的action的真實類路徑">
?<property name="業務對象">
??<ref local="代理對象"/>
?</property>
? </bean>
----------------------------------------------------------------------------------------------
第四種方式
1.在struts-config.xml中加入
 <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
 </controller>

2.applicationContext.xml中加入
? <bean name="/struts-config.xml中的action" class="struts-config.xml中的action的類路徑">
?<property name="業務對象">
??<ref local="代理對象"/>
?</property>
? </bean>
3.在web.xml中加入
 <listener>
? ?<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
? </listener>


以上是我所知道的四種配置方式,應該就這四種方式,本人感覺第三種配置方式比較好,通過struts的插件
方式把spring加過來,加多個spring的配置文件比較方更,只要在<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>的value中通過“,”分隔可以加多個spring的配置方件。

如果你有什么更好的方式,或有什么建議請給我留言。

總結

以上是生活随笔為你收集整理的struts+spring的配置方式总结的全部內容,希望文章能夠幫你解決所遇到的問題。

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