今天配置了半天,发现,事物不起效果,主要出现如下错误:
org.mybatis.spring.transaction.SpringManagedTransaction] - [JDBC Connection [com.jolbox.bonecp.ConnectionHandle@120fc40] will not be managed by SpringSqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@47eb1b] was not registered for synchronization because synchronization is not activeClosing non transactional SqlSession
后台看到大象的博文才找到答案,意思就是要排出spring servlet对@service注解的扫描,不然会导致事物配置失效,过滤排除@service注解就行了。
Spring MVC启动时的配置文件,包含组件扫描、url映射以及设置freemarker参数,让spring不扫描带有@Service注解的类。为什么要这样设置?因为servlet-context.
1 <!-- 定义控制器注解扫描包路径,控制器注解为 @Controller ,必须排除@Service注解 -->2 <context:component-scan base-package="com.teshehui.product">3 <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />4 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>5 </context:component-scan>
原标题:Springmvc + mybatis + spring 配置 spring事务处理
关键词:Spring