In the current new version of spring boot, @SpringBootApplication
is equivalent to @Configuration, @ComponentScan, @EnableConfiguration. What is the difference between @EnableAutoConfiguration and @ComponengScan? Since @EnableAutoConfiguration can automatically scan all beans under the path, then @ComponentScan seems to be unnecessary?
phpcn_u15822017-05-17 10:02:53
1.@EnableAutoConfiguration is mainly used to enable automatic configuration by scanning jar packages and configuring classes in META-INF/spring.factories and custom components for the current package and sub-packages (that is, those managed by spring) )
2.@ComponengScan is used to configure custom components (that is, managed by spring). You can specify the base path or BaseClass
If the class to be loaded is not under @EnableAutoConfiguration, it will not be loaded, and @ComponentScan is a class under the spring-context package, which has existed for a long time and is used in <context:component-scan>