search

Home  >  Q&A  >  body text

What is the difference between @EnableAutoConfiguration and @ComponengScan in Spring Boot?

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?

世界只因有你世界只因有你2775 days ago866

reply all(2)I'll reply

  • phpcn_u1582

    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>

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-17 10:02:53

    @ComponentScan can scan the packages in the jars you imported

    reply
    0
  • Cancelreply