@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
@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 ...