记一次找了一天的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的问题,反正别用排除包含标签