Spring自动事物代理

时间:2014-05-26 02:26:01   收藏:0   阅读:317
bubuko.com,布布扣
<!-- 定义事务管理器(声明式的事务) -->
<bean id="transactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref local="sessionFactory" />
   </property>
</bean> 

<bean id="transactionInterceptor"
   class="org.springframework.transaction.interceptor.TransactionInterceptor"> 
   <property name="transactionManager">
    <ref bean="transactionManager" />
   </property>
   <!-- 配置事务属性 -->
   <property name="transactionAttributes">
    <props>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
     <prop key="add*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="save*">PROPAGATION_REQUIRED</prop>
     <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
   </property>
</bean>

<!-- 自动代理 -->
<bean id="autoproxy"
   class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
   <!-- 可以是Service或DAO层(最好是针对业务层*Service) -->
   <property name="beanNames">
    <list>
     <value>*Service</value>
    </list>
   </property>
   <property name="interceptorNames">
    <list>
        <value>transactionInterceptor</value>
    </list>
   </property>
</bean> 
bubuko.com,布布扣

 

Spring自动事物代理,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!