Spring Framework FAQ: Top Questions
32. What is the purpose of @EnableAutoConfiguration in Spring?
@EnableAutoConfiguration
is an annotation used in Spring Boot to enable automatic configuration of the Spring application context based on the dependencies on the classpath.
📘 Behavior:
- Uses
spring.factories
to discover available auto-config classes. - Conditionally applies configuration using
@Conditional
annotations.
📥 Example:
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
🏆 Expected Output:
Spring configures beans like DataSource, Jackson, etc. based on dependencies.
🛠️ Use Cases:
- Simplifies project setup and reduces manual configuration.
- Custom starter creation and modular configuration.