springmvc事物管理 总结------- 只支持事物间 不支持事务内---???
2016-09-23 16:38
295 查看
通过配置 设置 事务和保存点
<!--④ 通过aop 配置 提供事物增强,让service下的 bean的 所有方法 拥有事物 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceMethod"
expression="execution(* com.ask.service..*(..))"
/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
<!-- 事物起作用 -->
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="com.ask.service.impl.TagServiceImpl.updateById" propagation="REQUIRED" isolation="DEFAULT" rollback-for="Exception"/>
<tx:method name="com.ask.service.impl.AnswerlistServiceImpl.updateById" propagation="REQUIRED" isolation="DEFAULT" no-rollback-for="Exception"/>
<!-- <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="Exception"/> -->
</tx:attributes>
</tx:advice>
通过注解设置保存点
@Autowired
TagService tagService;
// @Transactional(propagation=Propagation.REQUIRED,noRollbackFor={Exception.class, RuntimeException.class}) //,rollbackFor={Exception.class, RuntimeException.class}
@Transactional(propagation=Propagation.REQUIRED,noRollbackFor=Exception.class) //,rollbackFor={Exception.class, RuntimeException.class}
// @Transactional(propagation=Propagation.REQUIRED) //,rollbackFor={Exception.class, RuntimeException.class}
public int updateById(Map map) throws Exception{
answerListDao.updateById(map);
Map<String, Object> paras = new HashMap<String, Object>();
paras.put("title", "test001");
paras.put("id", "1");
之前有个问题一直困惑:
就是在 controller 里 调用 两个不同的Service ,但是不想通过组合的方式进行,一直在想能不能把两个Service 置于同一个事务控制下,可能是我想多了o(╯□╰)o
我在controller 里面调用这俩Service 在 实现里加上了
@Transactional(propagation=Propagation.REQUIRED)
为什么还是不能级联rollback
<!--④ 通过aop 配置 提供事物增强,让service下的 bean的 所有方法 拥有事物 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceMethod"
expression="execution(* com.ask.service..*(..))"
/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
<!-- 事物起作用 -->
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="com.ask.service.impl.TagServiceImpl.updateById" propagation="REQUIRED" isolation="DEFAULT" rollback-for="Exception"/>
<tx:method name="com.ask.service.impl.AnswerlistServiceImpl.updateById" propagation="REQUIRED" isolation="DEFAULT" no-rollback-for="Exception"/>
<!-- <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="Exception"/> -->
</tx:attributes>
</tx:advice>
通过注解设置保存点
@Autowired
TagService tagService;
// @Transactional(propagation=Propagation.REQUIRED,noRollbackFor={Exception.class, RuntimeException.class}) //,rollbackFor={Exception.class, RuntimeException.class}
@Transactional(propagation=Propagation.REQUIRED,noRollbackFor=Exception.class) //,rollbackFor={Exception.class, RuntimeException.class}
// @Transactional(propagation=Propagation.REQUIRED) //,rollbackFor={Exception.class, RuntimeException.class}
public int updateById(Map map) throws Exception{
answerListDao.updateById(map);
Map<String, Object> paras = new HashMap<String, Object>();
paras.put("title", "test001");
paras.put("id", "1");
之前有个问题一直困惑:
就是在 controller 里 调用 两个不同的Service ,但是不想通过组合的方式进行,一直在想能不能把两个Service 置于同一个事务控制下,可能是我想多了o(╯□╰)o
我在controller 里面调用这俩Service 在 实现里加上了
@Transactional(propagation=Propagation.REQUIRED)
为什么还是不能级联rollback
相关文章推荐
- Spring总结4—对持久层的支持(附:事务管理)
- 对Spring 容器管理事务支持的总结
- TransactionScope异常:该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- TransactionScope异常:该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- 关于TransactionScope出错:“与基础事务管理器的通信失败”的解决方法总结
- spring事务管理总结
- mysql 存储过程(我自己写的第一个存储过程,支持事务管理)2
- TransactionScope异常:该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- “该伙伴事务管理器已经禁止了它对远程/网络事务的支持”的解决方法
- SQL2K,DTC错误:"该伙伴事务管理器已经禁止了它对远程/网络事务的支持"的解决办法
- 该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- 该伙伴事务管理器已经禁止了它对远程/网络事务的支持。"。
- Spring总结之事务管理
- 该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- oracle事务管理相关问题总结
- 关于TransactionScope出错:“与基础事务管理器的通信失败”的解决方法总结
- TransactionScope异常:该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- 关于分布式事务得示:该伙伴事务管理器已经禁止了它对远程/网络事务的支持!
- MSDTC"该伙伴事务管理器已经禁止了它对远程网络事务的支持"的错误(转)
- 该伙伴事务管理器已经禁止了它对远程/网络事务的支持