Spring ImportSelector接口Demo
作者:互联网
这个接口要配合@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注解中使用这个实现类就可以了
标签:gxf,Spring,org,springframework,ImportSelector,Demo,import,Import,MySelector 来源: https://www.cnblogs.com/luckygxf/p/15418111.html