1.利用Bean继承的方式 :Spring 事务的配置如下:
txProxyTemplate的abstract="true",说明此类是一个抽象类,也可以不设置abstract属性,设置lazy-init="true"
也是把他当作抽象类,因为应用使用的是他的子bean,没必要的到代理类的实例。
transactionManager是为事务代理bean注入使用适用于Hibernte的事务管理器
<beans> <!-- on spring context starting up, frech the application context --> <bean id="beansUtil" class="com.krm.util.BeansUtil"></bean> <!-- Transaction template for Managers, from: http://blog.exis.com/colin/archives/2004/07/31/concise-transaction-definitions-spring-11/ --> <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="dataCollect">PROPAGATION_REQUIRED</prop> <prop key="getData*">PROPAGATION_REQUIRED</prop> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="sort*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="set*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="forward*">PROPAGATION_REQUIRED</prop> <prop key="reject*">PROPAGATION_REQUIRED</prop> <prop key="recover*">PROPAGATION_REQUIRED</prop> <prop key="recycle*">PROPAGATION_REQUIRED</prop> <prop key="freeze*">PROPAGATION_REQUIRED</prop> <prop key="transfer*">PROPAGATION_REQUIRED</prop> <prop key="change*">PROPAGATION_REQUIRED</prop> <prop key="build*">PROPAGATION_REQUIRED</prop> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="*WithLog">PROPAGATION_REQUIRED</prop> <prop key="prepare*">PROPAGATION_REQUIRED</prop> <prop key="init*">PROPAGATION_REQUIRED</prop> <prop key="import*">PROPAGATION_REQUIRED</prop> <prop key="fill*">PROPAGATION_REQUIRED</prop> <prop key="restore*">PROPAGATION_REQUIRED</prop> <prop key="oper*">PROPAGATION_REQUIRED</prop> <prop key