首页 > 代码库 > @EnableAutoConfiguration
@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@EnableAutoConfigurationpublic class BaseProviderApplication { public static void main(String[] args) { SpringApplication.run(BaseProviderApplication.class, args); }}
@EnableAutoConfiguration