自动配置
1. 介绍
springboot的核心功能之一就是自动配置,可以基于我们添加的jar依赖自动的对spring boot应用程序进行配置。spring boot的自动配置实现主要在spring-boot-autoconfiguration包中。我们在构架springboot应用的时候通常并没有额外的关注自动配置,但是自动配置使如何起作用的呢?其实springboot的自动配置使通过注解@EnableAutoConfiguration开启,因为springboot启动类中的注解@SpringBootApplication包含了@EnableAutoConfiguration所以我们只需要在启动类上加@SpringBootApplication就可以开启自动配置功能。
2. 自动配置源码
我们通过启动类注解@SpringBootApplication进去可以看到,该注解包含了@EnableAutoConfiguration。exclude、excludeName这两个属性其实就是@EnableAutoConfiguration注解里面的属性起的别名而已,所以这两个属性的作用和@EnableAutoConfiguration注解里面的是相同的。
@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
/**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
@AliasFor(annotation = EnableAutoConfiguration.class)
Class<?>[] exclude() default {};
/**
* Exclude specific auto-configuration class names such that they will never be
* applied.
* @return the class names to exclude
* @since 1.3.0
*/
@AliasFor(annotation = EnableAutoConfiguration.class)
String[] excludeName() default {};
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {};
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {};
@AliasFor(annotation = Configuration.class)
boolean proxyBeanMethods() default true;
}
我们继续进入@EnableAutoConfiguration注解的源码中。其中@AutoConfigurationPackage的作用就是将添加该注解的类所在的package作为自动配置package 进行管理。@Import(AutoConfigurationImportSelector.class)注解是关键,表示自动注解类的导入选择器,主要作用就是选择应用中哪些类需要加载到自动注解中。
@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
/**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
Class<?>[] exclude() default {};
/**
* Exclude specific auto-configuration class names such that they will never be
* applied.
* @return the class names to exclude
* @since 1.3.0
*/
String[] excludeName() default {};
}
我们进入到AutoConfigurationImportSelector类中,他的核心方法就是selectImports( )
@Override public String[] selectImports(AnnotationMetadata annotationMetadata) {
//判断是否开启自动注解,默认开启
if (!isEnabled(annotationMetadata)) {
return NO_IMPORTS;
}
//加载META-INF/spring-autoconfigure-metadata.properties文件中的配置
AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader
.loadMetadata(this.beanClassLoader);
//加载META-INF/spring.factoies中配置
AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(autoConfigurationMetadata,
annotationMetadata);
//配置信息转成字符串数组返回
return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
我们再进入到加载META-INF/spring.factoies的方法中,加载配置了EnableAutoConfiguration.class类下面的属性都会被加载
protected AutoConfigurationEntry getAutoConfigurationEntry(AutoConfigurationMetadata autoConfigurationMetadata, AnnotationMetadata annotationMetadata) {
//判断是否开启自动加载
if (!isEnabled(annotationMetadata)) {
return EMPTY_ENTRY;
}
AnnotationAttributes attributes = getAttributes(annotationMetadata);
//从META-INF/spring.factories配置文件中加载配置EnableAutoConfiguration.class类属性的值
List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
//移除重复项
configurations = removeDuplicates(configurations);
//获取配置了exclude、excludeName、spring.autoconfigure.exclude的类
Set<String> exclusions = getExclusions(annotationMetadata, attributes);
//排除不需要加载的类
checkExcludedClasses(configurations, exclusions);
configurations.removeAll(exclusions);
//过滤掉一些条件没有满足的
configurations = filter(configurations, autoConfigurationMetadata);
//事件广播,给自动配置监听器发送事件
fireAutoConfigurationImportEvents(configurations, exclusions);
return new AutoConfigurationEntry(configurations, exclusions);
}
META-INF/spring.factoies配置文件中自动配置项,可以发现springboot可以引入的依赖都有自动配置的实现。
# Auto Configureorg.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.CloudServiceConnectorsAutoConfiguration,
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.CassandraReactiveDataAutoConfiguration,
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,
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.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveRestClientAutoConfiguration,
org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,
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.RedisReactiveAutoConfiguration,
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.elasticsearch.rest.RestClientAutoConfiguration,
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,
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.http.HttpMessageConvertersAutoConfiguration,
org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,
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.groovy.template.GroovyTemplateAutoConfiguration,
org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,
org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,
org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,
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.mongo.embedded.EmbeddedMongoAutoConfiguration,
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,
org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,
org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,
org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,
org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,
org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,
org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,
org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,
org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,
org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,
org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration,
org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,
org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,
org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,
org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,
org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,
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.client.RestTemplateAutoConfiguration,
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,
org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,
org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,
org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration
我们随机选择一个进入看一下自动配置具体实现怎么起作用的;这里选择RedisAutoConfiguration来看
@Configuration(proxyBeanMethods = false)@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties(RedisProperties.class)
@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })
public class RedisAutoConfiguration {
@Bean
@ConditionalOnMissingBean(name = "redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
@Bean
@ConditionalOnMissingBean
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
从上面代码我们看到其中有一些条件注解
@ConditionalOnClass(RedisOperations.class)表示当classpath下面有RedisOperations类时起作用
@ConditionalOnMissingBean(name = "redisTemplate")表示IOC容器中没有redisTemplate 实例时起作用
springboot应用就是通过这些条件注解来实现自动配置功能的。常见的条件注解主要有一下:
条件注解:@Conditional类条件:@ConditionalOnClass(存在类) / @ConditionalOnMissingClass(不存在类)
属性条件:@ConditionalOnProperty
Bean条件:@ConditionalOnBean(存在bean) / @ConditionalOnMissingBean(不存在bean)/ @ConditionalOnSingleCandidate(只存在一个候选)
资源条件:@ConditionalOnResource
加载顺序:@AutoConfigureBefore/@AutoConfigureAfter/@AutoConfigureOrder
3.自定义自动配置
我们先创建三个工程分别为
great :实现具体功能的包,被配置进springboot应用中使用。
zycfc-spring-boot-autoconfigure:实现自动配置功能的类,用于使greet包能够在springboot应用中起作用
demo:springboot应用,运行业务程序的包。
在greet包中我们定义GreatApplicationRunner 类,用于在springboot应用程序启动时有系统调用run方法,实现业务处理。
/** * @description <描述>
* @author jiafeng
* @date 2020年3月19日 下午8:33:51
*/
public class GreatApplicationRunner implements ApplicationRunner {
private String name;
public GreetApplicationRunner() {
this("great");
}
public GreetApplicationRunner(String name) {
this.name = name;
}
public void run(ApplicationArguments args) throws Exception {
System.out.println("Hello every one:" + this.name);
}
}
在zycfc-spring-boot-autoconfigure里面定义ZycfcAutoConfiguration类,用于控制GreetApplicationRunner对象的生效条件。其中满足两个条件时GreatApplicationRunner会生效;第一个条件@ConditionalOnClass(GreatApplicationRunner.class)当classpath下存在时生效,第二个条件 @ConditionalOnMissingBean(GreatApplicationRunner.class)当容器中没有该类实例时生效。
首先在zycfc-spring-boot-autoconfigure工程里面引入great包依赖,然后现实自动配置类
<dependency> <groupId>com.zycfc.greet</groupId>
<artifactId>great</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope> <!-- provided表明该包只在编译和测试的时候用 -->
</dependency>
@Configuration@ConditionalOnClass(GreatApplicationRunner.class)
public class ZycfcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(GreatApplicationRunner.class)
public GreatApplicationRunner greatApplicationRunner() {
return new GreatApplicationRunner();
}
}
在zycfc-spring-boot-autoconfigure的META-INF/spring.factoies文件中配置自动启动类,使springboot应用能够加载到配置以便加载。
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.zycfc.auto.ZycfcAutoConfiguration
最后在demo的pom文件中引入上面两个jar包的依赖
<dependency> <groupId>com.zycfc.greet</groupId>
<artifactId>great</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zycfc.auto</groupId>
<artifactId>zycfc-spring-boot-autoconfigure</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
运行demo的启动启动程序
@SpringBootApplicationpublic class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("启动完成");
}
}
执行结果:
. ____ _ __ _ _
/\ / ___"_ __ _ _(_)_ __ __ _
( ( )\___ | "_ | "_| | "_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
" |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2020-03-20 12:52:27.022 INFO 119620 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on ZZ-WZ112019 with PID 119620 (E:java_workdemo argetclasses started by jiafeng in E:java_workdemo)
2020-03-20 12:52:27.024 INFO 119620 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-03-20 12:52:27.779 INFO 119620 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-20 12:52:27.787 INFO 119620 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-20 12:52:27.787 INFO 119620 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-20 12:52:27.852 INFO 119620 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-20 12:52:27.852 INFO 119620 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 798 ms
2020-03-20 12:52:27.970 INFO 119620 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService "applicationTaskExecutor"
2020-03-20 12:52:28.087 INFO 119620 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ""
2020-03-20 12:52:28.088 INFO 119620 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.334 seconds (JVM running for 1.656)
Hello every one:great
启动完成
下面我们尝试不满足自动配置条件时是否会加载
在demo的启动类中实例化GreatApplicationRunner实例,则自动配置就不会生效执行。
@SpringBootApplicationpublic class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("启动完成");
}
@Bean
public GreatApplicationRunner greatApplicationRunner() {
return new GreatApplicationRunner("not auto");
}
}
运行程序:发现执行的是我们在启动类里面创建的GreatApplicationRunner实例,并非自动配置执行的GreatApplicationRunner实例
. ____ _ __ _ _
/\ / ___"_ __ _ _(_)_ __ __ _
( ( )\___ | "_ | "_| | "_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
" |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2020-03-20 13:05:06.429 INFO 120132 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on ZZ-WZ112019 with PID 120132 (E:java_workdemo argetclasses started by jiafeng in E:java_workdemo)
2020-03-20 13:05:06.431 INFO 120132 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-03-20 13:05:07.208 INFO 120132 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-20 13:05:07.215 INFO 120132 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-20 13:05:07.216 INFO 120132 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-20 13:05:07.279 INFO 120132 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-20 13:05:07.279 INFO 120132 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 820 ms
2020-03-20 13:05:07.396 INFO 120132 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService "applicationTaskExecutor"
2020-03-20 13:05:07.502 INFO 120132 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ""
2020-03-20 13:05:07.503 INFO 120132 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.335 seconds (JVM running for 1.666)
Hello every one:not auto
启动完成
至此,我们自动配置讲解完了
以上是 自动配置 的全部内容, 来源链接: utcz.com/z/514573.html