【實用小技巧】spring與springmvc自動掃描包重復的問題解決


spring對應配置文件為:

	<!-- 配置自動掃描的包,此時要排除Controller -->
	<context:component-scan base-package="com.lw">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>

springmvc對應的配置文件為:

	<!-- user-default-filters 與 include-filter搭配使用 實現僅僅掃描Controller注解 -->
	<context:component-scan base-package="com.lw" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>

注:屬性user-default-filters官方介紹:

Attribute : use-default-filters
Indicates whether automatic detection of classes annotated with @Component, @Repository, 
 @Service, or @Controller should be enabled. Default is "true".


 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM