spring中对方法的事务拦截配置

[quote]在applicationContext.xml中配置如下:[/quote]

<!--hibernate 事务-->
<bean id="HibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 事务拦截,以下面固定格式开头的方法都在事务包含之列 -->
<tx:advice id="HiberbateTxAdvice"
transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="insert*" rollback-for="Throwable" />
<tx:method name="update*" rollback-for="Throwable" />
<tx:method name="delete*" rollback-for="Throwable" />
<tx:method name="add*" rollback-for="Throwable" />
<tx:method name="save*" rollback-for="Throwable" />
<tx:method name="remove*" rollback-for="Throwable" />
<tx:method name="modify*" rollback-for="Throwable" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 事务覆盖范围:com.kedacom.kdkk.service包下面的所有类 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceOperation"
expression="execution(* com.kedacom.kdkk.service..*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation"
advice-ref="HiberbateTxAdvice" />
</aop:config>

[quote]注:当方法内抛出运行时异常时,事务便会回滚。[/quote]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值