主要原因就是两个配置文件:
SpringMVC.xml自身加载的时候,注意:
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<!-- 加载controller的时候,不加载service,因为此时事物并未生效,若此时加载了service,那么事物无法对service进行拦截 -->
<context:component-scan base-package="org.jeecgframework.web.*,weixin.*">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>
然后配置事务的xml:
<!-- 自动扫描dao和service包(自动注入) -->
<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>
修改了事务就可以正确的回滚~~~
本文介绍了SpringMVC中如何正确配置控制器与服务层的自动扫描,通过分隔配置文件来确保事务能够正确地对Service层进行拦截及回滚。

3250

被折叠的 条评论
为什么被折叠?



