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. 汇编的WEAK关键字

    一般来说,这个关键字使用在IMPORT和EXPORT这两个声明段. ////////////////////////////////////////////////////////////////// ...

  2. sublime2常用设置

    设置文本字体格式 • Preferences -> Setting-User • 加入设置:"font_face" : "courier new", &q ...

  3. Postman中使用Postman Interceptor 发送带Cookie 的请求

    使用Postman 发送Cookie 的请求时,发现无法发送成功, 显示"Restricted Header (use Postman Interceptor)" 提示. 网上搜了 ...

  4. Linux系统——本地yum仓库安装

    一.yum仓库概述 yum是基于rpm包管理,能够从指定的服务器自动下载rpm包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无需繁琐地一次次下载.安装. 二.yum仓库安装的方式 ...

  5. SQL Server扩展属性的增、删、改、查

    使用 sql 语句创建表时,可以使用系统存储过程 sp_addextendedproperty 给字段添加描述说明. sp_addextendedproperty 语法: sp_addextended ...

  6. Hive的metastore

    hive --service metastore 默认端口是9083 <property> <name>hive.metastore.uris</name> < ...

  7. jquery Treeview插件的使用及复选框的级联

    本文是对jquery的Treeview插件使用的实例介绍 效果图如下: 文件结构如下:

  8. NOIP2019前的训练记录

    \(April\):肛多项式,学\(FWT\)一个小时无果后背了六个公式,看来证明又得咕很久了

  9. igraph Tutorial

      igraph Tutorial¶   参考http://www.cs.rhul.ac.uk/home/tamas/development/igraph/tutorial/tutorial.html ...

  10. 从toString()方法到Object.prototype.toString.call()方法

    一.toString方法和Object.prototype.toSting.call()的区别 var arr=[1,2]; 直接对一个数组调用toString()方法, console.log(ar ...