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的配置方式总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle学习笔记(一)------o
- 下一篇: oracle学习笔记(二)------函