Spring beans should be considered by “@ComponentScan

I am using

  • SonarQube Enterprise Edition Version 9.2.4 (build 50792)
  • Scanner:
  • SonarLint for IntelliJ
  • sonar-maven-plugin:

I have a Spring Boot application and the scanner produces the warning “Spring beans should be considered by “@ComponentScan”” for the following class:

package com.company.a.b.c.impl;

public class MyService {...}

Then the Application class:

package com.company.a

public class MyApplication {...}

I am aware of this answer False positive for Spring java:S4605 for multi-module projects. "component is not visible by @ComponentScan"

and since my project is a multi-module project, I also tried adding an empty @Component annotation and also a @Component with different values, once “com.company.a.b”, once “com.company.a.b.c.impl” but SonarLint still displays the warning.

Please note that the application is started as expected.

1 Like


Welcome to the community!

To be clear, you’re reporting a false positive?


1 Like

Thanks :slight_smile:
Yes, since my application is working as expected I believe that this is a false positive.

1 Like

Hey @cbertoldi_p,

Thanks for reporting the issue. As you noted, there are known limitations to that rule and the Java analyzer but if you are seeing the issue in SonarLint, then there might be something else going on.

Just to clarify: are you running SonarLint in connected mode? (assuming connected to Sonarlcoud here)

Hey Dorian_Burihabwa, yes, I am running SonarLint in connected mode.

Hi @cbertoldi_p,
In your first message, you mentioned setting up a @ComponentScan with and without package values to mitigate the issue but that it did not work.

Just so that we can reproduce the issue, can you confirm that your setup looks something like this:

  + com.company.a
    - MyService.java <-- annotated with @Service
    - SomeEmptyClass.java <-- annotated with @ComponentScan
  + com.company.a.b.c.impl
    - MyApplication.java <-- annotated with @SpringBootApplication

And yet an issue is still raised on MyService.java?

Hi @Dorian_Burihabwa
almost, in my setup there is no SomeEmptyClass annotated with @ComponentScan

Hi @cbertoldi_p,

I am not sure I understand: Did you try the solution from the other thread of adding the @ComponentScan annotation to some class in the module that is not covered?

You mention the @Component annotation but I am not sure this is supposed to help here. Did you mean @ComponentScan?