时间:2022-09-20 09:27:12 | 栏目:JAVA代码 | 点击:次
我们项目往往会引入其他项目的依赖,造成功能冲突的类,我们想把这些类排除掉,不注入到我们项目IoC容器中,
@ComponentScan(basePackages = "com.xxx",excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {
xxxPublisher.class,
xxxAdvice.class,
xxxService.class})})
其中这三个类,我不需要加载到我们项目中,需要指明type=FilterType.ASSIGNABLE_TYPE
不指定type类型执行classes={xxx...} 排除不了
public enum FilterType {
ANNOTATION,
ASSIGNABLE_TYPE,
ASPECTJ,
REGEX,
CUSTOM;
}
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@EnableScheduling
@ComponentScan(basePackages = {"com.hudai.platform.sms.vendor","com.hudai.platform.scp"}, excludeFilters =
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = com.hudai.platform.scp.alert.config.RestTemplateConfig.class))
public class SmsVendorApplication {
public static void main(String[] args) {
SpringApplication.run(SmsVendorApplication.class, args);
}
}
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = com.hudai.platform.scp.alert.config.RestTemplateConfig.class))
这段是经典~