@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