Spring 支持的事务传播行为

来源:互联网 发布:淘宝怎么看注册时间 编辑:程序博客网 时间:2024/05/29 11:42


在spring.xml中配置

<!-- 事务管理类 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 定义通知  通知的代码  spring已经实现 --><!-- 上面的id名为 id="transactionManager" 下面的 transaction-manager="transactionManager"可以不写--><tx:advice id="myAdvise" transaction-manager="transactionManager"><tx:attributes><!-- propagation="REQUIRED"  方法和方法之间存在父子关系REQUIRED 默认   父方法没有事务创建一个事务  有事务使用父方法当前事务REQUIRES_NEW   不管父方法是否存在事务  都会新建事务SUPPORTS  父方法存在事务  使用当前事务   没有事务 使用jdbc的事务(自动提交) NOT_SUPPORTED  不管父方法中是否存在事务  都不会使用父方法中的事务(挂起事务) MANDATORY   必须在事务环境中运行  父方法没有事务  抛出异常 No existing transaction found for transaction marked with propagation 'mandatory' NEVER  父方法中不能存在事务   有事务就抛出异常 --><tx:method name="Update*" propagation="SUPPORTS"/><tx:method name="save*" propagation="MANDATORY"/><tx:method name="delete*"/><tx:method name="*" read-only="true"/></tx:attributes></tx:advice>