Spring与SpringMVC重复扫描问题


在SpringMVC.XML有以下的配置:

《!--扫描@controller注解--》

<context:component-scan base-package="com.xxx.controller">

   <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />

</context:component-scan>

 

把最终的包写上,而不能这样写base-package="com.xxx"。这种写法对于:include-filter来讲它都会扫描。而不是仅仅扫描@controller

如果这样,一般会导致一个常见的错误---事务不起作用。解决的方法:添加:use-default-filters=”false”

<context:component-scan base-package="com.xxx" use-default-filters="false"> 

  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 

</context:component-scan>

 

 在Spring.xml配置

<context:component-scan base-package="com.xxx"> 

  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />

</context:component-scan>

 

这样的意思 不包括@controller


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM