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