Spring 声明式事务的配置方式(二)

本文介绍了一种基于Spring框架的事务管理配置优化方法,通过使用继承思想简化配置文件,适用于多业务模块场景。该方法通过定义抽象的事务模板并让具体业务模块继承此模板来减少重复代码。

这种配置方法与方法一的区别主要是采用了继承的思想,在业务模块较多的情况下,能够简化配置文件的代码

由于在不同的配置方式中,只有配置事务时的代码存在变化,其它的配置不再累述

<bean id="transactionBizTemplate" abstract="true"

        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

        <property name="transactionManager" ref="transactionManager"></property>

        <!—配置事务属性,具体配置方法和第一种相同,就不再累述-->

        <property name="transactionAttributeSource"

           ref="transactionAttributeSource"></property>

</bean>

<!—开始配置具体的业务模块,设置parent为模板Bean--> 

<bean id="usersBiz" parent="transactionBizTemplate">

          <property name="proxyInterfaces"

              value="org.companyname.myprj.service.IUsersService"></property>

       <property name="target" ref="usersService"></property>

</bean>

<bean id="itemsBiz" parent="transactionBizTemplate">

           <property name="proxyInterfaces"

              value="org.companyname.myprj.service.IItemsService"></property>

        <property name="target" ref="itemsService"></property>

</bean>

<!-- 设置模板Bean的abstract值为true,保证不会被初始化 -->

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值