1. 程式人生 > >PROPAGATION_REQUIRED及其他6種事務傳播行為種類

PROPAGATION_REQUIRED及其他6種事務傳播行為種類

<!-- 定義事務攔截器bean-->
<bean id="transactionInterceptor"
   class="org.springframework.transaction.interceptor.TransactionInterceptor">
   <!-- 事務攔截器bean需要依賴注入一個事務管理器-->
   <property name="transactionManager" ref="transactionManager" />
   <property name="transactionAttributes">
    <!-- 下面定義事務傳播屬性-->
    <props>
     <prop key="save*">PROPAGATION_REQUIRED</prop>
     <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
   </property>
</bean>

<bean id="managerTemplate" abstract="true" lazy-init="true">
<property name="teamDao">
   <ref bean="teamDao" />
</property>
<property name="studentDao">
   <ref bean="studentDao" />
</property>    
</bean>

<bean id ="manager" class="com.zd.service.impl.Manager" parent="managerTemplate" />

<!-- 定義BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
     <!-- 指定對滿足哪些bean name的bean自動生成業務代理 -->
     <property name="beanNames">
            <!-- 下面是所有需要自動建立事務代理的bean-->
            <list>
                <value>manager</value>
            </list>
            <!-- 此處可增加其他需要自動建立事務代理的bean-->
     </property>
        <!-- 下面定義BeanNameAutoProxyCreator所需的事務攔截器-->
        <property name="interceptorNames">
            <list>
                <!-- 此處可增加其他新的Interceptor -->
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>