自动配置原理

配置文件到底能写什么?怎么写?自动配置原理;

配置文件能配置的属性参照

 

自动配置原理:

1)、Spring Boot启动的时候加载主配置类,开启了自动配置功能@EnableAutoConfiguration

2)、@EnableAutoConfiguration

  利用EnableAutoConfigurationImportSelector给容器中导入一些组件?

  可以插件selectImports()方法的内容;

  List<String>configurations = getCandidateConfigurations(annotationMetadata,attributes);获取候选的配置

    SpringFactoriesLoader.loadFactoryNames()

    扫描所有jar包类路径下 META-INF/spring.factories

    把扫描到的这些文件的内容包装成properties对象

    从properties中获取到EnableAutoConfiguration.class类(类名)对应的值,然后把他们添加在容器中

  将类路径下META-INF/spring.factories里面配置的所有EnableAutoConfiguration的值加入到了容器中:

  每一个这样的xxxAutoConfiguration类都是容器中的一个组件,都加入到容器中;用他们来做自动配置

3)、每一个自动配置类进行自动配置功能

posted @ 2020-10-19 06:23  Tsugar  阅读(163)  评论(0编辑  收藏  举报