@SpringBootApplication 注解:
    1、@SpringBootConfiguration 是一个类级别的注释,它指示此类提供了应用程序配置。
    2、@EnableAutoConfiguration 使用自动配置。主要组成注解:①、②。
    ①、@AutoConfigurationPackage作用:自动配置一系列的包。主要组成注解:a。
    a、@Import(``AutoConfigurationPackages``.``Registrar``.``class``)
    作用:导入AutoConfigurationPackages.Registrar 组件。利用Registrar给容器中导入一系列的组件,默认是启动类MainApplication下的所有包。
    原理:new PackageImports(metadata).getPackageNames() 它获取主类包路径信息,
    .toArray(new String[0])保存到数组内,然后封装到registry。Registrar就是把某个包下的所有组件批量注解。

    1. @Override
    2. public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    3. register(registry, new PackageImports(metadata).getPackageNames().toArray(new String[0]));
    4. }

    ②、@Import``(``AutoConfigurationImportSelector``.``class``)
    作用:导入 AutoConfigurationImportSelector 组件。通过其中的 selectImports() 方法得到所有配置的数组。
    原理:通过 selectImports() 方法中
    1、利用selectImports() 方法中 getAutoConfigurationEntry(annotationMetadata);给容器中批量导入一些组件
    2、调用List configurations = getCandidateConfigurations(annotationMetadata, attributes)获取到所有需要导入到容器中的配置类
    3、利用工厂加载 Map> loadSpringFactories(@Nullable ClassLoader classLoader);得到所有的组件
    4、从META-INF/spring.factories位置来加载一个文件。
    默认扫描我们当前系统里面所有META-INF/spring.factories位置的文件
    pring-boot-autoconfigure-2.3.4.RELEASE.jar包里面也有META-INF/spring.factories

    1. @Override
    2. public String[] selectImports(AnnotationMetadata annotationMetadata) {
    3. if (!isEnabled(annotationMetadata)) {
    4. return NO_IMPORTS;
    5. }
    6. AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);
    7. return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
    8. }

    2.3.1、@SpringBootApplication注解源码分析 - 图1
    3、@ComponentScan指定组件扫描。
    文件里面写死了spring-boot一启动就要给容器中加载的所有配置类

    1. spring-boot-autoconfigure-2.3.4.RELEASE.jar/META-INF/spring.factories
    2. # Auto Configure
    3. org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    4. org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
    5. org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
    6. org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
    7. org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
    8. org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
    9. org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
    10. org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
    11. org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration,\
    12. org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
    13. org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
    14. org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
    15. org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
    16. org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
    17. org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
    18. org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
    19. org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
    20. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\
    21. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
    22. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
    23. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
    24. org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
    25. org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
    26. org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,\
    27. org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration,\
    28. org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
    29. org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
    30. org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
    31. org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
    32. org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\
    33. org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\
    34. org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\
    35. org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\
    36. org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\
    37. org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\
    38. org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration,\
    39. org.springframework.boot.autoconfigure.data.r2dbc.R2dbcRepositoriesAutoConfiguration,\
    40. org.springframework.boot.autoconfigure.data.r2dbc.R2dbcTransactionManagerAutoConfiguration,\
    41. org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
    42. org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\
    43. org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
    44. org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\
    45. org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\
    46. org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration,\
    47. org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
    48. org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\
    49. org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
    50. org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
    51. org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\
    52. org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
    53. org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
    54. org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
    55. org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
    56. org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
    57. org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
    58. org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
    59. org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
    60. org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
    61. org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
    62. org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
    63. org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
    64. org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
    65. org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
    66. org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
    67. org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
    68. org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
    69. org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
    70. org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\
    71. org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\
    72. org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
    73. org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
    74. org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
    75. org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration,\
    76. org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
    77. org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\
    78. org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
    79. org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\
    80. org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\
    81. org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\
    82. org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
    83. org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\
    84. org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
    85. org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
    86. org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
    87. org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration,\
    88. org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,\
    89. org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,\
    90. org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,\
    91. org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,\
    92. org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
    93. org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
    94. org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\
    95. org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\
    96. org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\
    97. org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,\
    98. org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration,\
    99. org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
    100. org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
    101. org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\
    102. org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\
    103. org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\
    104. org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
    105. org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
    106. org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
    107. org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
    108. org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
    109. org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
    110. org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
    111. org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
    112. org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\
    113. org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\
    114. org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\
    115. org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\
    116. org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
    117. org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\
    118. org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\
    119. org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\
    120. org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\
    121. org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\
    122. org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
    123. org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
    124. org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\
    125. org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
    126. org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
    127. org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
    128. org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
    129. org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
    130. org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration