Spring Boot的自动配置的原理
Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器。
1、Maven下载源码
通过 dependency:sources 该命令可以下载该项目中所有的依赖的包的源码。
2、源码分析
在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->META-INF-->spring.factories
1 # PropertySource Loaders 2 org.springframework.boot.env.PropertySourceLoader=\ 3 org.springframework.boot.env.PropertiesPropertySourceLoader,\ 4 org.springframework.boot.env.YamlPropertySourceLoader 5 6 # Run Listeners 7 org.springframework.boot.SpringApplicationRunListener=\ 8 org.springframework.boot.context.event.EventPublishingRunListener 9 10 # Application Context Initializers 11 org.springframework.context.ApplicationContextInitializer=\ 12 org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\ 13 org.springframework.boot.context.ContextIdApplicationContextInitializer,\ 14 org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\ 15 org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer 16 17 # Application Listeners 18 org.springframework.context.ApplicationListener=\ 19 org.springframework.boot.ClearCachesApplicationListener,\ 20 org.springframework.boot.builder.ParentContextCloserApplicationListener,\ 21 org.springframework.boot.context.FileEncodingApplicationListener,\ 22 org.springframework.boot.context.config.AnsiOutputApplicationListener,\ 23 org.springframework.boot.context.config.ConfigFileApplicationListener,\ 24 org.springframework.boot.context.config.DelegatingApplicationListener,\ 25 org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener,\ 26 org.springframework.boot.logging.ClasspathLoggingApplicationListener,\ 27 org.springframework.boot.logging.LoggingApplicationListener 28 29 # Environment Post Processors 30 org.springframework.boot.env.EnvironmentPostProcessor=\ 31 org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\ 32 org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor 33 34 # Failure Analyzers 35 org.springframework.boot.diagnostics.FailureAnalyzer=\ 36 org.springframework.boot.diagnostics.analyzer.BeanCurrentlyInCreationFailureAnalyzer,\ 37 org.springframework.boot.diagnostics.analyzer.BeanNotOfRequiredTypeFailureAnalyzer,\ 38 org.springframework.boot.diagnostics.analyzer.BindFailureAnalyzer,\ 39 org.springframework.boot.diagnostics.analyzer.ConnectorStartFailureAnalyzer,\ 40 org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnalyzer,\ 41 org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,\ 42 org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer 43 44 # FailureAnalysisReporters 45 org.springframework.boot.diagnostics.FailureAnalysisReporter=\ 46 org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter