Spring Mvc Spring Mybatis 全注解事物配置,Service层事物不回滚

spring-context.xml中,配置不扫描Coontroller
<!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
<context:component-scan base-package="com.pds.j2ee"><!-- base-package
如果多个,用“,”分隔 -->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
Spring-mvc.xml中,配置只扫描Controller
<!-- 使用Annotation自动注册Bean,只扫描@Controller -->
<context:component-scan base-package="com.pds.j2ee" use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
PS:另需注意,如果配置文件中配置了多个事物,需在Service层 注解事物时指定事物的名称
@Transactional("transactionManager3")
Service层方法体重 不可以使用 try catch 快,否则事物不会回滚,需要 throws Exception
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值