困扰我一天的问题得以解决
是配置的问题
- aspringmvc.xml配置 只扫描controller 注解
<!--开启注解扫描,只扫描controller注解-->
<context:component-scan base-package="lss" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:include-filter>
</context:component-scan>
- application.xml配置 扫描除了controller的注解
<context:component-scan base-package="lss">
<!--配置哪些注解不扫描-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:exclude-filter>
</context:component-scan>
问题就是没有理解透<context:component-scan>标签中会出现include和exclude的子标签
- include 相当与白名单,白名单里的会被扫描到,但是不在黑名单的一样会呗扫描到 所以一定要加use-default-filters=“false” 让除了他以外的不会被扫描到 之前没有加导致spring注入事物了 但是到springmvc在次扫描把没注入事物的覆盖了前面注入事物的。
- exclude 相当于黑名单 配置之后就不会在扫描这个包