您的位置:首页 > 编程语言 > Java开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring mvc 事务 管理
相关文章推荐