Spring 采用基于XML方式配置事务

来源:互联网 发布:数据挖掘 十大算法knn 编辑:程序博客网 时间:2024/04/30 20:04

 

使用配置:

 

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

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

</bean>

<aop:config>

  <aop:pointcut id="transactionPointcut" expression="execution(*   

                                                                           cn.itcast.service..*.*(..))"/>

  <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>

</aop:config>

<tx:advice id="txAdvice" transaction-manager="txManager">

    <tx:attributes> <!--get开始的方法不要事务-->

      <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/>

      <tx:method name="*"/> <!--启用默认事务行为,数据库默认级别-->

    </tx:attributes>

</tx:advice>