Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器。

1.1.1.   Maven下载源码

通过 dependency:sources 该命令可以下载该项目中所有的依赖的包的源码。

1.1.2.   源码分析

org.springframework.boot.SpringApplication:

org.springframework.core.io.support.SpringFactoriesLoader:

由此可见,读取该配置文件来加载内容。

1.1.3.   Spring.factories文件

 # Initializers

 org.springframework.context.ApplicationContextInitializer=\

 org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\

 org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer

 # Application Listeners

 org.springframework.context.ApplicationListener=\

 org.springframework.boot.autoconfigure.BackgroundPreinitializer

 # Auto Configuration Import Listeners

 org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\

 org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener

 # Auto Configuration Import Filters

 org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\

 org.springframework.boot.autoconfigure.condition.OnClassCondition

 # Auto Configure

 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\

 org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\

 org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\

 org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\

 org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\

 org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\

 org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\

 org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration,\

 org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\

 org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\

 org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\

 org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\

 org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.ldap.LdapDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\

 org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\

 org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\

 org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\

 org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\

 org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\

 org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\

 org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\

 org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\

 org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\

 org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\

 org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\

 org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\

 org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\

 org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\

 org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\

 org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\

 org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\

 org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\

 org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\

 org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\

 org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\

 org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\

 org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\

 org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\

 org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\

 org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\

 org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\

 org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\

 org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\

 org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\

 org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\

 org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\

 org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration,\

 org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\

 org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\

 org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\

 org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\

 org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\

 org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration,\

 org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration,\

 org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration,\

 org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration,\

 org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration,\

 org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\

 org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\

 org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration,\

 org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration,\

 org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration,\

 org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration,\

 org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\

 org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\

 org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\

 org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\

 org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration,\

 org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,\

 org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,\

 org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration,\

 org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration

 # Failure analyzers

 org.springframework.boot.diagnostics.FailureAnalyzer=\

 org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\

 org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\

 org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer

 # Template availability providers

 org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\

 org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\

 org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\

 org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\

 org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\

 org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider

1.1.4.   举例:Redis的自动配置

从上述的配置中可以看出,org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration是Redis的自动配置。

内容:

1.1.5.   条件注解

Spring Boot的自动配置的原理的更多相关文章

  1. Spring Boot的自动配置的原理浅析

    一.原理描述 Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器. 二. ...

  2. Spring boot 的自动配置

    Xml 配置文件 日志 Spring Boot对各种日志框架都做了支持,我们可以通过配置来修改默认的日志的配置: #设置日志级别 logging.level.org.springframework=D ...

  3. Spring Boot的自动配置原理及启动流程源码分析

    概述 Spring Boot 应用目前应该是 Java 中用得最多的框架了吧.其中 Spring Boot 最具特点之一就是自动配置,基于Spring Boot 的自动配置,我们可以很快集成某个模块, ...

  4. 了解Spring Boot的自动配置

    摘自:https://www.jianshu.com/p/ddb6e32e3faf Spring Boot的自动配置给开发者带来了很大的便利,当开发人员在pom文件中添加starter依赖后,mave ...

  5. Spring Boot的自动配置

    Spring Boot的自动配置 --摘自https://www.hollischuang.com/archives/1791 随着Ruby.Groovy等动态语言的流行,相比较之下Java的开发显得 ...

  6. 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置

    在上篇博客初识Spring Boot框架中我们初步见识了SpringBoot的方便之处,很多小伙伴可能也会好奇这个Spring Boot是怎么实现自动配置的,那么今天我就带小伙伴我们自己来实现一个简单 ...

  7. spring boot 系列之六:深入理解spring boot的自动配置

    我们知道,spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate是不是在Classpath里面?如果是,并 ...

  8. Spring Boot 排除自动配置的 4 种方法,关键时刻很有用!

    Spring Boot 提供的自动配置非常强大,某些情况下,自动配置的功能可能不符合我们的需求,需要我们自定义配置,这个时候就需要排除/禁用 Spring Boot 某些类的自动化配置了. 比如:数据 ...

  9. 自定义spring boot的自动配置

    文章目录 添加Maven依赖 创建自定义 Auto-Configuration 添加Class Conditions 添加 bean Conditions Property Conditions Re ...

随机推荐

  1. 增强MyEclipse的代码自动提示功能

      一般在Eclipse ,MyEclipse代码里面,打个foreach,switch等 这些,是无法得到代码提示的(不信自己试试),其他的就更不用说了,而在Microsoft Visual Stu ...

  2. Oracle 性能调优 10053事件

    思维导图 10053事件概述 我们在查看一条SQL语句的执行计划时,只看到了CBO最终告诉我们的执行计划结果,但是我们并不知道CBO为何要这样做. 特别是当执行计划明显失真时,我们特别想搞清楚为什么C ...

  3. B-、B+、B*树

    B-树:多路搜索树,每个结点存储M/2到M个关键字,非叶子结点存储指向关键字范围的子结点:所有关键字在整颗树中出现,且只出现一次,非叶子结点可以命中: B+树:在B-树基础上,为叶子结点增加链表指针, ...

  4. C++基础之头文件和源文件的关系

    今天找了个解析xml的开源C++项目tinyxml,按照网上的说法去编译,但是一直编译不通过,"无法打开头文件tinyxml.h",但是明明我在工程底下有了这个文件,对于我这种初学 ...

  5. cpu-》内存-》磁盘

    cpu相当于计算机大脑负责计算以及发送执行命令:内存相当于人的记忆是临时存储:磁盘相当于笔记本,负责永久存储数据: 当系统需要调用硬盘当中的数据时,会将硬盘数据读入内存供cpu进行处理.cpu只会读取 ...

  6. java模拟http/https post请求

    1.Post请求失败的代码 try { HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = respon ...

  7. JavaScript-dom4 date string 事件绑定

    内置date <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  8. Python中常用技巧整理

    Python中os.path的妙用  http://xpleaf.blog.51cto.com/9315560/1736956

  9. Java 为什么要使用反射(通俗易懂的举例)

    Java反射最大的好处就是能在运行期间,获得某个类的结构.成员变量,用来实例化. 下列是具体使用场景:假如我们有两个程序员,一个程序员在写程序的时候,需要使用第二个程序员所写的类,但第二个程序员并没完 ...

  10. pyinstaller 打包生成的exe文件,在其他电脑上报错

    解决方法: 1.第一种情况,在打包的时候不要加参数-w,看一下执行exe文件后出现的报错再看下一步的行动 2.应该是需要装一个VC 2015 x64(下载地址:https://www.microsof ...