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