@ComponentScan
Learn how does the Spring search for beans found in different packages.
We'll cover the following
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
Get hands-on with 1400+ tech skills courses.