Senior
Where does Spring Boot look for components if there is no @ComponentScan?
sobes.tech AI
Answer from AI
If the @ComponentScan annotation is not specified in a Spring Boot application, the framework by default scans for components in the same package as the class annotated with @SpringBootApplication (or @Configuration), and all its subpackages.
This means that the package structure and the location of the main application class influence the scan scope. If components are outside this package tree, they need to be explicitly specified using @ComponentScan.
Example:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Here, Spring Boot will look for components in the MyApplication package and all its subpackages.