无法回滚的时间过程
使用了spring mvc+mybatis时抛出异常无法回滚,因为使用的纯java配置所以和网上的教程略有不同之后配合官方文档解决。
解决方法
引用了spring官方文档的一句话
@EnableTransactionManagement and tx:annotation-driven/ look for @Transactional only on beans in the same application context in which they are defined. This means that, if you put annotation-driven configuration in a WebApplicationContext for a DispatcherServlet, it checks for @Transactional beans only in your controllers and not in your services. See MVC for more information.
大概意思是要把注解了@Transactional的类和你的controller(调用者)要放置在一个容器中,所以controller,service和@EnableTransactionManagement都要注册在同一个容器内。
参考我的情况
我的问题在于将Controller放置在了一个容器而service(被注解@Transactional的类)放置在了另外一个容器,所以导致事物无法回滚。