SpringMVC事务失效的解决方法

本文介绍了SpringMVC中如何正确配置控制器与服务层的自动扫描,通过分隔配置文件来确保事务能够正确地对Service层进行拦截及回滚。

主要原因就是两个配置文件:


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>


修改了事务就可以正确的回滚~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值