Medium java spring

22. Difference between @EnableAutoConfiguration and @Import?

Sample answer: "@Import loads @Bean definitions from configuration classes I name explicitly. @EnableAutoConfiguration turns on Boot's discovery: it finds candidate classes from the imports files and applies the ones whose conditions match. So one is explicit, the other is classpath-driven and conditional." Editor's note: internally, auto-configuration is also an import, done through an import selector. This comes from the source code and is not confirmed in the docs.

Sources (2)
  1. Composing Java configurations: Using @Import
  2. Using auto-configuration