SpringMVC事務失效的解決方法

主要緣由就是兩個配置文件:web


SpringMVC.xml自身加載的時候,注意:
spring


<!-- 自動掃描controller包下的全部類,使其認爲spring mvc的控制器 -->express

<!-- 加載controller的時候,不加載service,由於此時事物並未生效,若此時加載了service,那麼事物沒法對service進行攔截 -->spring-mvc

<context:component-scan base-package="org.jeecgframework.web.*,weixin.*">mvc

<context:exclude-filter type="annotation"spa

expression="org.springframework.stereotype.Service" />component

</context:component-scan>xml



而後配置事務的xml:事務


<!-- 自動掃描dao和service包(自動注入) -->it

<context:component-scan base-package="org.jeecgframework.core.common.dao.*" />

<context:component-scan base-package="org.jeecgframework.core.common.service.*" />


<!-- 加載service,此時要排除要controller,由於controller已經spring-mvc中加載過了 -->

<context:component-scan base-package="org.jeecgframework.web.*,weixin.*">

<context:exclude-filter type="annotation"

expression="org.springframework.stereotype.Controller" />

</context:component-scan>


修改了事務就能夠正確的回滾~~~

相關文章
相關標籤/搜索