【面试题】:Spring IOC容器在boot中也是存在的对吧,那有一些Bean我不想在启动时就注入IOC容器,这种情况有遇到过吗?
【个人理解】:目前还没遇到,不过要是实现的话,在启动类上加上@ComponentScan注解,在value中写上指定的:*.class是可以实现的【参见2.4小结】,或继承TypeExcludeFilter ,重写match方法,如默认会加载com.test.TestService这个bean,则重写的方法中,
public class MyTypeExcludeFilter extends TypeExcludeFilter {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
throws IOException {
if("com.test.TestService".equals(metadataReader.getClassMetadata().getClassName())){
return false;
}
return true;
}
}
或者直接在boot配置文件中添加,其是支持的【但是我没细究如何配置,这个百度下应该就有】,如下: