`

spring事务管理

 
阅读更多
spring管理事务提交


http://blog.csdn.net/huangbiao86/article/details/6588780

修改applicationContext.xml加入事务管理

<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
">

<!-- 事务管理 -->
<!-- 定义一个事务管理器 -->
<bean id="myHibTransactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory" >
   </property>
</bean>
<!--定义事务通知-->
<tx:advice id="txAdvice" transaction-manager="myHibTransactionManager">
   <!--声明事务规则-->
   <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="insert*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED"/>
    <!--对其他方法要求只读事务-->
    <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
   </tx:attributes>
</tx:advice>
<aop:config>
   <!--定义一个切面,即定义哪些方法应用这些规则-->
   <aop:pointcut id="bizMethods" expression="execution(* com.accp.ke.biz.*.*(..))"/>
   <!--将事务通知和切面组合(织入)-->
   <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods"/>
</aop:config>





修改struts-config.xml配置文件,使用代理action类
type="org.springframework.web.struts.DelegatingActionProxy"

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
  	<set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/>
 </plug-in>





参考:
1.http://blog.csdn.net/qjyong/article/details/4824179
2.http://www.blogjava.net/robbie/archive/2009/04/05/264003.html


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics