spring boot本身就是一个服务于spring框架的框架,能够简化配置文件,快速构建微博应用,内置tomcat,无需打包部署,直接运行。
而其中我认为最方便的特性就是约定优于配置,使得程序员能更加专注于业务逻辑。
其中EnableAntoConfiguration默认对依赖的starter进行自动
springboot 自动装配的原理是:
1.SpringApplication.run 执行流程中有refreshContext(context),内部会解析我们的配置类上的标签,实现自动装配功能的注解@EnableAntoConfiguration
2.会解析@EnableAntoConfiguration这个注解里面的@Import引入的配置类@AntoConfigurationImportSelector
3.@AntoConfigurationImportSelector这个类中有方法SpringFactoriesLoder.loadFactoryNames(getStringFactoriesLoaderFactoryClass(),getBeanClasLoader());作用就是读取jarbao中的项目中的META-INF/spring.factories文件
4.spring.factories 配置了要自动装配的 Configuration 类。
03-27
1495
09-09