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

这种配置方式是利用BeanNameAutoProxyCreater自动创建事务代理,这种配置方式主要是采用拦截器的原理

 

<!-- 配置事务拦截器 -->

<bean id="transatioinInterceptor"

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

      <!-- 事务的传播属性 -->

        <property name="transactionAttributeSource"

            ref="transactionAttributeSource"></property>

        <!-- 事务拦截器中需要依赖注入一个事务管理器 -->

 

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

</bean> 

 

 

<!-- 定义BeanNameAutoProxyCreator,该Bean无需被引用,因此没有id属性 -->

 

 

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

        <property name="interceptorNames" value="transatioinInterceptor"></property>

        <property name="beanNames">

           <list>

               <value>*Service</value>

           </list>

        </property>

</bean>

<!-- 这个bean后处理器会根据事务拦截器为目标的bean自动创建事务代理 -->

你可能感兴趣的:(Spring 声明式事务的配置方式(三))