準備三個框架結合的lib包
Spring3結合Struts2的步驟如下:
1:開啟Struts2結合Spring3,在struts.xml中添加如下語句:
java代碼:
1
|
|
2:在web.xml中添加listener,如下:
java代碼:
1
2
3
4
|
<listener> <listener- class > org.springframework.web.context.ContextLoaderListener</listener- class > </listener> |
3:在web.xml中指定需要初始讀取的spring配置文件,如下:
java代碼:
1
2
3
4
|
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> </context-param> |
5.當然別忘了加上Struts2自己的filter
4:在struts.xml中Action配置的時候,如下:
java代碼:
1
2
3
|
<action name= "testAction" class = "springBeanName" > <result name= "success" >/index.jsp</result> </action> |
5:在Spring中正常定義Bean就可以了,把Action定義成為Bean,如下:
java代碼:
1
2
3
|
<bean id= "testAction" class = "com.bjpowernode.test.web.TestActioin" > <property name= "ebi" ref= "testEbi" /> </bean> |
6:在Struts的Action中,就可以通過依賴注入的方式來注入需要使用的接口了。
總結
以上所述是小編給大家介紹的struts+spring+hibernate三個框架的整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://blog.sina.com.cn/s/blog_9c6852670102ww9l.html