spring容器指定某個包不被掃描


在spring的配置類上加上注解,實現某個包不被掃描:

代碼:

@ComponentScan(value = "com.yinshan",excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX,pattern = "com.yinshan.spring.service.*")})

 注解ComponentScan中value是指被掃描的類,excludeFilters定義過濾規則:使用正則表達式地方式排出service包下面的內容;

測試類:

 打印結果:

 未獲取到指定bean;

詳情可見spring官方文檔:

https://docs.spring.io/spring/docs/5.2.7.RELEASE/spring-framework-reference/core.html#beans-scanning-filters


免責聲明!

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



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