Spring boot configuration issues with sonar

‘ABCService’ is not reachable by @ComponentsScan or @SpringBootApplication. Either move it to a package configured in @ComponentsScan or update your @ComponentsScan configuration.

This the error message I get in 9 critical bugs in Sonarqube analysis, one for each Service and Controller.

Though @Autowire and dependency injection is working fine but still Sonar seems to be complaining.

The rule in question causing the issue is:

Spring beans should be considered by “@ComponentScan”

Spring beans belonging to packages that are not included in a
@ComponentScan configuration will not be accessible in the Spring
Application Context. Therefore, it’s likely to be a configuration
mistake that will be detected by this rule. Note: the @ComponentScan
is implicit in the @SpringBootApplication annotation, case in which
Spring Boot will auto scan for components in the package containing
the Spring Boot main class and its sub-packages.

Since @SpringBootApplication is has component scan which scans main class package and all it’s sub packages as well this issue shouldn’t come.

Leave a Reply

2 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

This is a SonarQube bug, it doesn’t handle SpringBootApplication properly. You should report it here : https://community.sonarsource.com/c/bug


To quote from Rules from Sonar, @ComponentScan is used to determine which Spring Beans are available in the application context. The packages to scan can be configured thanks to the basePackageClasses or basePackages (or its alias value) parameters. If neither parameter is configured, @ComponentScan will consider only the package of the class annotated with it. When @ComponentScan is used on a class belonging to the default package, the entire classpath will be scanned. This will slow-down the start-up of the application and it is likely the application will fail to start with an BeanDefinitionStoreException because you ended up scanning the… Read more »