Spring+Mybatis @Transactional注解事务不生效
@Transactional声明式事务配置:
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 声明式事务配置 -->
<tx:annotation-driven transaction-manager="transactionManager" />
----------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------
添加以上配置后,在类上声明了@Transactional(如下图),但是在action层中调用MenuHeadInsMapServiceImpl类的方法A,发现方法A并没有进入事务。
解决办法:
1.在spring的配置文件applicationContext.xml中,扫描包时排除Controller:
<context:component-scan base-package="com.cg.*.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
2.在springMVC配置文件servlet.xml中,扫描包时排除Service:
<context:component-scan base-package="com.cg.*.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
主要是参考了这篇文章:http://blog.csdn.net/z69183787/article/details/37819627