这个接口要配合@Import注解一起使用

1 import org.springframework.context.annotation.ImportSelector;
2 import org.springframework.core.type.AnnotationMetadata;
3 
4 public class MySelector implements ImportSelector {
5     @Override
6     public String[] selectImports(AnnotationMetadata importingClassMetadata) {
7         return new String[] {"com.gxf.normal.NormalBean1", "com.gxf.normal.NormalBean2"};
8     }
9 }

实现这个接口,可以指定需要注入到spring ioc容器里面的类

import com.gxf.importdemo.MySelector;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Import(MySelector.class)
@Configuration
public class ImportConfig {
}

再在@Import注解中使用这个实现类就可以了

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2021-11-23
  • 2021-06-16
猜你喜欢
  • 2021-11-03
  • 2021-12-09
  • 2021-10-24
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案