Closing non transactional SqlSession导致spring事务不生效

记一次找了一天的bug!!!!spring版本5.1.8.RELEASE

错误:Closing non transactional SqlSession!父子容器扫描重复问题

网上看了很多解决办法,主流的解决办法是:

1.在applicationContext.xml中配置不扫描controller注解:

<context:component-scan base-package="com.lang">
        <!--配置哪些注解不扫描-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

2.在applicationContext-mvc.xml中配置只扫描controller注解:

<!--开启注解扫描,只扫描Controller注解-->
    <context:component-scan base-package="com.lang">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

问题就出现在这!!!!这个 include-filter好像TMD不生效,子容器把带事务增强的父容器覆盖了!!!!!

so!!!!!!我是这么处理的,applicationContext-mvc.xml中就这么扫:

<!--开启注解扫描,只扫描Controller注解-->
    <context:component-scan base-package="com.lang.controller"/>

applicationContext.xml中就这么扫:

<!--开启注解的扫描,希望处理service和dao,controller不需要Spring框架去处理-->
    <context:component-scan base-package="com.lang.service"/>

各扫各的包,不要用什么排除包含标签,真的坑啊!!!!!!!!!!

就算使用了use-default-filters="false",还会有404的问题,反正别用排除包含标签

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值