springboot启动的时候排除加载某些bean
@SpringBootApplication的exclude 专门用来排除auto-configuration 也就是我们说的自动配置的类的。例如:
@SpringBootApplication(exclude = KafkaAutoConfiguration.class)
1
如果在@SpringBootApplication排除非自动配置类,会报错
用@SpringBootApplication(exclude = RibbonRule.class)排除类@bean注入的类的时候报错
The following classes could not be excluded because they are not auto-configuration classes.....
如果想要排除我们自定义的@Bean,可以用
@ComponentScan(excludeFilters= {@ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE, value= {RedisUtil.class})})
1
指定包的扫描范围:
@ComponentScan(basePackages = {"com.test"},
excludeFilters={@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE,
value= {org.xxx.core.common.xxl.XXLConfig.class
})})
1
2
3
4
2
3
4
上次更新: 2024/01/30, 15:08:57