5配置事务管理

为了实现事务管理功能,需要在spring配置文件applicationContext。xml中进行配置。本系统采用了基本AOP的事务管理配置,配置流程如下所示。

(1)<beans>标记中添加AOP所需的常用命名空间声明:

 xmlns_htt : p : / /www. springframework. org/schema/beans 
xmlns : xsi=http : / / www. w3. org/2001/xmlschema-instance 
xmlns : aop_http : / / www. springframework. org/schema/aop 
xmlns : p.http : / / www. springframework. org/schema/p 
xmlns : tx_http : / /www. springframework. org/schema/tx 
xsi : schemalocation=http : / / www. springframework. org/schema/beans 
http : / / www. springframework. org/schema/beans/spring-beans-3. 1. xsd 
http : / / www. springframework. org/schema/aop 
http : / / www. springframework. org/schema/aop/spring-aop-3. 1. xsd 
http : //www. springframework. org/schema/tx/spring-tx. xsd, ; > 
(2)使用声明式事务,需要提供声明事务管理器。
使用MyEc卸se向导给项目添加Spring和Hibemate支持后,会自动在Spring配置文1 
中声明一个Hibemate事务管理器,如下所示:
<!一声明事务管理器一〉
<bean 
id="transactionjuIanager"class-"org. springframework': orm 
. hibernated. Hibernate TransactionManager"> 
<property name="session Factory"'ref = : session Factory"/ >. · T'tii, : :, 
. </bean> 
(3)定义事务通知时需要指定一个事务管理器,然后在其属性中声明事务规则:
iq tw=-
wn,〈!一定义事务逾知 · -〉.-:”引燕裱羹纛莠蓁蓑襄苎琴棼幕嵘;
<tx : advi. ce id= nt×Advice"transacti : on-manager-"transactionManagc_-.' 
<tx : attributes> 
<tx : method name-n* r'propagation-"REQUIRED"/ > 

</tx : attributes> 
,41 
</tx : advi ce> 
在定义事务传播规则时,对所有的方法应用REQUIRED事务规则,表示当前方法必
运行在一个事务环境中,如果一个现有事务正在运行中,该方法将运行在这个事务中’
则,就要开始一个新的事务。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值