解决Spring事务不回滚

来源:互联网 发布:做淘宝真的比上班累吗 编辑:程序博客网 时间:2024/06/05 11:43

在主容器中(applicationContext.xml),将Controller的注解排除掉 

<context:component-scan base-package="com.microdata"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/><context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/></context:component-scan>


在SpringMVC.xml中,将Service注解排除掉 

 <context:component-scan base-package="com.microdata"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />  </context:component-scan>


要回滚事务,还需要的抛出运行时异常,

或者在catch 语句块中 加上 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();



1 0
原创粉丝点击