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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM