@EnableAutoConfiguration

Posted shuimx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@EnableAutoConfiguration相关的知识,希望对你有一定的参考价值。

1. spring文档

解释一:

Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined. For example, If you have tomcat-embedded.jar on your classpath you are likely to want a TomcatEmbeddedServletContainerFactory (unless you have defined your own EmbeddedServletContainerFactory bean).

For example, it will be used when scanning for @Entity classes. It is generally recommended that you place @EnableAutoConfiguration in a root package so that all sub-packages and classes can be searched.

解释二:

@EnableAutoConfiguration annotation auto-configures the beans that are present in the classpath. This simplifies the developers work by guessing the required beans from the classpath and configure it to run the application. This annotation is part of the spring boot project.

 

根据依赖、类路径、自定义的bean,猜测会用到的bean,从而自动配置。

一般在根包定义中使用。

 

@ComponentScan("com.example")
@Configuration @EnableAutoConfiguration
public class BaseProviderApplication { public static void main(String[] args) { SpringApplication.run(BaseProviderApplication.class, args); } }

 

以上是关于@EnableAutoConfiguration的主要内容,如果未能解决你的问题,请参考以下文章

@EnableAutoConfiguration 标签使用

Spring Boot 中的 @ComponentScan 和 @EnableAutoConfiguration 有啥区别?

springBoot @EnableAutoConfiguration深入分析

springboot的@EnableAutoConfiguration起作用的原理

@EnableAutoConfiguration和@SpringbootApplication注解

Spring Boot源码分析@EnableAutoConfiguration注解@AutoConfigurationImportSelector注解的处理