1. 编写实现ImportSelector的类

/**
* @author 70KG
* @Title: SelectImportBean
* @Description:
* @date 2018/7/22下午4:59
* @From www.nmyswls.com
*/
public class SelectImportBean implements ImportSelector { @Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
return new String[]{"com.nmys.story.springCore.springioc.importBean.Fish","com.nmys.story.springCore.springioc.importBean.Pig"};
} }

2. 编写配置类

/**
* @author 70KG
* @Title: Config
* @Description:
* @date 2018/7/22下午4:41
* @From www.nmyswls.com
*/
@Configuration
// 会自动向容器中加入实例化后的bean,默认的id是bean的全类名
@Import(value = {Dog.class, Cat.class, SelectImportBean.class})
public class ImportBeanConfig { }

3. 测试类

public class Test01 {

    @Test
public void test() { // IOC容器创建(容器类似一个Map)
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ImportBeanConfig.class); System.out.println("IOC容器初始化完成。。。。。"); // 从容器中获取所有的bean的ID
String[] definitionNames = ac.getBeanDefinitionNames(); for (String name : definitionNames) {
System.out.println("------->" + name);
} }
}

4. 测试结果

IOC容器初始化完成。。。。。
------->org.springframework.context.annotation.internalConfigurationAnnotationProcessor
------->org.springframework.context.annotation.internalAutowiredAnnotationProcessor
------->org.springframework.context.annotation.internalRequiredAnnotationProcessor
------->org.springframework.context.annotation.internalCommonAnnotationProcessor
------->org.springframework.context.event.internalEventListenerProcessor
------->org.springframework.context.event.internalEventListenerFactory
------->importBeanConfig
------->com.nmys.story.springCore.springioc.importBean.Dog
------->com.nmys.story.springCore.springioc.importBean.Cat
------->com.nmys.story.springCore.springioc.importBean.Fish
------->com.nmys.story.springCore.springioc.importBean.Pig

5. ImportSelector用于向容器中导入指定的类。

最新文章

  1. MHA高可用+VIP 集群故障转移(已测试成功)
  2. Linux系统上安装mysql数据库
  3. ubuntu亮度无法自动调节终极解决方案
  4. Android Log日志文件的分析、查看
  5. .net简单页面后台绑定下拉框,按钮,分页 前台aspx页面
  6. 【拓扑排序】【HDU3231】【Box Relations】
  7. jQuery tmpl index
  8. 前端开发在IOS端遇到的一个诡异问题(Delegate 失效)
  9. IE console.log 调试状态
  10. ThreadPoolExecutor参数
  11. 2015年蓝桥杯省赛A组c++第5题(回溯算法填空)
  12. 2018/04/25 PHP7的编译安装
  13. Java之24种设计模式-UML-模型图解读
  14. Web前端js下载流文件
  15. stdafx
  16. R语言字符串替换
  17. 使用 requests 发送 POST 请求
  18. UVA 10462 Is There A Second Way Left?(次小生成树&Prim&Kruskal)题解
  19. Tomcat服务器启动失败:Could not publish server configuration for Tomcat v8.0 Server at localhost. Multiple Contexts have a path of
  20. JS计算字符长度、字节数 -- 转

热门文章

  1. python实践项目九:操作文件-修改文件名
  2. oracle11g数据库导入导出方法教程
  3. #redis 安装命令
  4. bootstrap.min.css.map作用
  5. 小程序的组件插槽使用slot===以及小程序多个插槽使用方法 三步骤
  6. 扩展JS
  7. VBA编程图表(二十一)
  8. vue实现滑块滑动校验
  9. 重置文件reset
  10. css小技巧 --> 单标签实现单行文字居中,多行文字居左