My Spring boot application is not scaning my components (controllers)
Many Spring Boot developers have annotated their spring boot application class with @SpringBootApplication
annotation. But we noticed that sometimes it failed to scan components. We might have added @ComponentScan annotation too.
But we see still the component scan is not happening. What is the reason?
In fact, The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration
and @ComponentScan with their default attributes.
If we get into these kind of situations, just remember that the component scan default behaviour happens
only in the same package and in its sub package. If your controllers or components are in different, dont forget to override
your component scan default configurations. Here is the sample code on how to override the default behavour.
@SpringBootApplication(scanBasePackages = "com.java2novice")
|
Or you can specify multiple packages as shown below:
@SpringBootApplication(scanBasePackages = {"com.java2novice", "com.simplebro"})
|
|