简介
说明
本文介绍SpringBoot如何排除某个指定的类(不将它扫描到容器中)。
本文说的这种情况是排除本来使用@Component等加入容器的类。如果想要排除自动配置(即:自定义starter,通过spring.factories来指定的配置类),见此文:SpringBoot--排除自动配置类--方法/实例_IT利刃出鞘的博客-CSDN博客
需求
使用 RuoYi(若依)源码,不想用 RuoYi 自带的权限管理(ShiroConfig) ,但是不删除它,只是不让它生效。
方案1:@ComponentScan
@ComponentScan(excludeFilters =
{@ComponentScan.Filter(
type = FilterType.REGEX,
pattern = {com.ruoyi.framework.config.ShiroConfig"})})
@SpringBootConfiguration
public class RuoYiApplication {
...
}
1.在@ComponentScan 中指定 excludeFilters 属性。该属性指定排除的Bean/类。
2.使用正则表达式方式(FilterType.REGEX)排除类 "com.ruoyi.framework.config.ShiroConfig"
方案2:@ComponentScans
@ComponentScans说明
@ComponentScans由所有的@Com