花費我整整一個下午和一個晚上的時間才搞定,如果有不合適的地方還請高手指點迷津,小弟感激不禁~
環境JDK5,tomcat6.0,mysql5.0,win xp
配置的方式有很多種,這裏我只介紹一種啦
這些是我的一點經驗教訓
Struts1.2,Spring2.0,Hibernate3.1
1.注意action繼承自org.springframework.web.context.WebApplicationContext
在action中使用ActionSupport的getWebApplicationContext()方法獲取WebApplicationContext對象,再由該對象獲取bean實例
2.action配置爲
注意在struts中和spring中都要配置,注意action種的type發生改變
Struts-config.xml
<action attribute="loginForm" input="/login.jsp"
name="loginForm" path="/login" scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
</action>
applicationContext.xml
<bean name="/login" class="com.david.struts.action.LoginAction" scope="prototype"></bean>
3.在web.xml中配置監聽器
用ContextLoaderListener初始化spring容器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
用contextConfigLocation制定spring配置文件的位置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
4.用strust1的plug-in擴展
注意這個是spring的配置文件
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
5.整合Hibernate時候就不說什麼了
整個過程要注意的幾點
1.添加Struts按照正常添加,我的是1.2
2.添加Spring要注意,不要選擇orm/dao/hibernate3,導入core,aop,和web三個就可以了,添加結束後,要把spring.jar手動導入到編譯路徑中去,這個可以去網上找,在spring的發佈包中就有
3.添加Hibernate所有的三個包core,advanced,還有Spring2.0 orm/dao/hibernate3
作者:滿天飛雪
QQ:409394295
E-Mail:[email protected]
源碼實例可以取我的資源下載:http://download.csdn.net/source/237383