Spring Boot之@EnableAutoConfiguration源码解读

@EnableAutoConfiguration:使Springboot自动配置。可以找到@SpringBootApplication所在类的包。然后将该包下的所有子包纳入spring容器。即com.doublechen.helloworld.xxx。并自动扫描。

spring boot 在启动时,会根据meta-inf/spring.factories找到相应的第三方依赖,并将这些依赖引入本项目。

a.自己写的代码,spring boot 通过@SpringBootConfiguration自动帮我们配置。

b.三方依赖 通过spring-boot-autoconfiguration-2.0.3.RLEASE.jar中的META-INF/spring.factories进行声明,然后开启使用。

c.Configuration:标识此类是一个配置类、将此类纳入springioc容器。  

@EnableConfigurationProperties(HttpEncodingProperties.class): 通过HttpEncodingProperties将编码更改。

@ConditionOnProperty(prefix = "spring.http.encoding",value = "enabled" match)当属性满足要求时,条件成立。

在配置文件:application.properties中加入debug=true,可以查看那些自动装配使用,那些禁用。

Positive matches列表 表示spring boot 自动开启了哪些装配。

Negative matches列表 表示spring boot 在此时并没有启用的自动装配。

原文地址:https://www.cnblogs.com/jccjcc/p/14174646.html