在spring的配置類上加上注解,實現某個包不被掃描:
代碼:
@ComponentScan(value = "com.yinshan",excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX,pattern = "com.yinshan.spring.service.*")})
注解ComponentScan中value是指被掃描的類,excludeFilters定義過濾規則:使用正則表達式地方式排出service包下面的內容;
測試類:
打印結果:
未獲取到指定bean;
詳情可見spring官方文檔: