@ComponentScan

Learn how does the Spring search for beans found in different packages.

Spring does a component scan to search for the beans that it manages. In a Spring application, the @ComponentScan annotation without any argument tells Spring to scan the current package as well as any sub-packages that might exist. Spring detects all classes marked with the @Component, @Repository, @Service, and @Controller annotations during component scan.

@SpringBootApplication

In a Spring application, @ComponentScan is used along with the @Configuration annotation. In a Spring Boot application, component scan happens implicitly. The @SpringBootApplication annotation is a combination of three annotations:

  • @Configuration

  • @EnableAutoConfiguration

  • @ComponentScan

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.