这种配置方法与方法一的区别主要是采用了继承的思想,在业务模块较多的情况下,能够简化配置文件的代码
由于在不同的配置方式中,只有配置事务时的代码存在变化,其它的配置不再累述
<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,保证不会被初始化 -->