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. Linux文件操作相关命令

    1.创建文件夹: [root@izuf6ih01h8fzeziddwkfdz sm]# mkdir a 创建一个名为a的文件夹 2.创建文件: [root@izuf6ih01h8fzeziddwkfd ...

  2. LayoutInflater的动态增加控件

    在实际开发中LayoutInflater这个类是非常有用的,它的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout下xml布局文件. 而findView ...

  3. HTTP来源地址

    HTTP来源地址(referer,或HTTP referer),是HTTP表头的一个字段,用来表示从哪儿链接到目前的网页,采用的格式是URL. 换句话说,借着HTTP来源地址,目前的网页可以检查访客从 ...

  4. Keras + Ubuntu环境搭建

    安装Theano (环境参数:Ubuntu 16.04.2  Python 2.7) 安装 numpy 和 scipy 1.sudo apt-get install python-numpy pyth ...

  5. sql server常用性能计数器

    https://blog.csdn.net/kk185800961/article/details/52462913?utm_source=blogxgwz5 https://blog.csdn.ne ...

  6. ruby lib文件夹作用

    require 'lib/test_module' #lib/test_module.rb module TestModule end

  7. vue-cli中的.babelrc文件介绍

    转载自:http://www.cnblogs.com/ye-hcj/p/7071850.html { // 此项指明,转码的规则 "presets": [ //个人认为多此一举 [ ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  9. HDU - 4725 The Shortest Path in Nya Graph(拆点+Dijkstra)

    题意:N个点,每个点有一个层号L,相邻的两层 Li 与 Li+1 之间的距离为C.另外给出M条无向边,求从点1到点N的最短路. 分析:同一层之间的两点距离并不是0,这是一个小坑.依次把相邻两层的所有点 ...

  10. 漂亮的输出-----prettytable和colorama的使用

    Python通过prettytable模块将输出内容如表格方式整齐输出,python本身并不内置,需要独立安装该第三方库. 1 pip install PrettyTable 1 #源码安装 2 wg ...