1. 程式人生 > >Spring+Mybatis @Transactional註解事務不生效

Spring+Mybatis @Transactional註解事務不生效

排除 context mage prop span 文件 action aso eight

@Transactional聲明式事務配置:

  <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
  </bean>

  <!-- 聲明式事務配置 -->
  <tx:annotation-driven transaction-manager="transactionManager" />

----------------------------------------------------------------分割線---------------------------------------------------------------------------------------------------------------------------------

添加以上配置後,[email protected](如下圖),但是在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

Spring+Mybatis @Transactional註解事務不生效