xml代码:
<bean id="proxyService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="myTransactionManager"/></property>
<property name="target">
<ref local="itemService"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="itemService" class="com.xxx.services.IServiceImpl">
<property name="itemMasterDAO"><ref local="itemMasterDAO"/></property>
</bean>
系统中有多个service,但我们的事务策略大部分都是一样的,难道非要每个service都要写一个这样的代理配置么?当然不是..
看下面代码:
xml代码:
<!-- Transactional proxy for the services -->
<bean id="baseTxProxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="itemService" parent="baseTxProxy">
<property name="target">
<bean class="ItemServiceImpl" autowire="byName"/>
</property>
</bean>
<bean id="proxyService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="myTransactionManager"/></property>
<property name="target">
<ref local="itemService"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="itemService" class="com.xxx.services.IServiceImpl">
<property name="itemMasterDAO"><ref local="itemMasterDAO"/></property>
</bean>
系统中有多个service,但我们的事务策略大部分都是一样的,难道非要每个service都要写一个这样的代理配置么?当然不是..
看下面代码:
xml代码:
<!-- Transactional proxy for the services -->
<bean id="baseTxProxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="itemService" parent="baseTxProxy">
<property name="target">
<bean class="ItemServiceImpl" autowire="byName"/>
</property>
</bean>