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

posted @ 2020-06-13 23:03  丙炎  阅读(1670)  评论(0)    收藏  举报