读书人

配备式事务:struts与spring的二种整合

发布时间: 2012-12-25 16:18:28 作者: rapoo

配置式事务:struts与spring的二种整合方式

?

??? 使用两个配置文件:applicationContext.xml和hibernate.cfg.xml
???

?? 1.新建web项目
??
?? 2.添加hibernate支持和spring支持 (顺序可以颠倒)
??
?? 3.使用工具支持进行数据库的反射操作
??
?? 4.编写dao接口,实现dao接口
??
??
?? 5.修改spring配置文件,管理持久层
??
??
?? 6.编写biz接口和实现接口(不编写事务代码)
??
?? 7.修改spring配置文件,管理业务层代码
??
?? (针对业务接口进行测试)
??
?? 8.添加struts支持,实现mvc架构:acton类,formbean类,jsp页面等
??
?? 9.修改spring配置文件,管理action类,
???? <bean name="/booklist" ref="BookinfoBizImpl"></property>
? </bean>
??
?? 10.修改struts配置文件,把action配置的类修改成委托代理类
???? <action parameter="list" path="/booklist"
??type="org.springframework.web.struts.DelegatingActionProxy"
??validate="false">
??<forward name="success" path="/booklist.jsp" />
?</action>
?
?
?(三个框架整合完毕)
?
?11.把spring交给web服务器管理,修改web.xml
?
?? <context-param>
???<param-name>contextConfigLocation</param-name>
???<param-value>
????/WEB-INF/classes/applicationContext.xml
???</param-value>
??</context-param>
?
??<listener>
???<listener-class>
????org.springframework.web.context.ContextLoaderListener
???</listener-class>
??</listener>
??
?
?12.如果使用了延迟加载数据.解决延迟加载异常,修改web.xml
?? <filter>
???<filter-name>openSessionInViewFilter</filter-name>
???<filter-class>
????org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
???</filter-class>
??</filter>
?
??<filter-mapping>
???<filter-name>openSessionInViewFilter</filter-name>
???<url-pattern>/*</url-pattern>
??</filter-mapping>
??
??
??
==================================================================

?? struts与spring的第二种整合方式:
????
???? 1.编写一个spring配置文件action-servlet,用于管理action类
????
??????? <beans xmlns="http://www.springframework.org/schema/beans"
???xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
???xmlns:aop="http://www.springframework.org/schema/aop"
???xmlns:tx="http://www.springframework.org/schema/tx"
???xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">
??
???<!-- 表示层 -->
??
???<bean name="/booklist" ref="BookinfoBizImpl"></property>
???</bean>
??
??</beans>
??
?2.修改struts-config.xml,配置中央控制器的处理类
?
?? <!-- 配置中央控制器的处理类;不使用ActionServlet类 -->
??<controller>
???<set-property property="processorClass"
????value="org.springframework.web.struts.DelegatingRequestProcessor" />
??</controller>
??
?? 3.添加一个struts插件,用于读取spring的action类配置文件
??
???? <!-- struts插件类,用于读取spring配置文件 -->
??<plug-in
???className="org.springframework.web.struts.ContextLoaderPlugIn">
???<set-property property="contextConfigLocation"
????value="/WEB-INF/classes/action-servlet.xml" />
??</plug-in>
??
?4.把前面配置的struts与spring的配置代码去掉
???


??
??
?
??
??
??
????

读书人网 >编程

热点推荐