关于Spring+mybatis使用@Transactional注解事物没有生效的问题

控制台日志信息:

was not registered for synchronization because synchronization is not active JDBC Connection。

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@19e35973]

出现以上信息说明spring的事物被覆盖掉了,通常是因为在spring.xml中扫描了一次@service注解后,springmvc.xml又重新扫描@service的注解,把事物覆盖掉了。

解决办法:

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

在springmvc.xml中不扫描@Service注解就可以了

原文地址:https://www.cnblogs.com/yyxq/p/10869634.html