Spring Boot: @ComponentScan vs @EnableAutoConfiguration

What is the difference between @ComponentScan and @EnableAutoConfiguration in Spring Boot? 🎯 @ComponentScan finds and registers your classes annotated with: @Component, @Service, @Repository, @Controller (from the package where your main class exists and its sub-packages) 🎯 @EnableAutoConfiguration automatically configures Spring Boot beans based on: dependencies present in the classpath application properties 🎯 Example If you add spring-boot-starter-web, @EnableAutoConfiguration automatically configures things like: embedded Tomcat DispatcherServlet JSON converter And @ComponentScan will detect your UserController, UserService, etc. ------------------------------------------------------------------- Conclusion @ComponentScan = find my code beans @EnableAutoConfiguration = configure framework beans automatically ✅ #SpringBoot #Java #Microservices #BackendDevelopment #SpringFramework #AutoConfiguration #ComponentScan #SoftwareEngineering #InterviewPreparation #JavaDeveloper #RestAPI #TechInterview #CleanCode #DeveloperLife

To view or add a comment, sign in

Explore content categories