@ComponentScan
Explore how to use the @ComponentScan annotation for scanning beans within Spring applications. Understand how to specify packages, use include and exclude filters, and manage bean detection across multiple packages to enhance component management.
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
@SpringBootApplication by default, searches the package where it is present, as well as all the sub-packages. If a bean is present in a package other than the base package or its ...