Autowiring for bean class inspection complains about beans instantiated via @ComponentScan with constant variable
I am having a problem with the detection of autowired spring beans in intellij.
I have a set of annotated spring beans in the package "com.mycompany.mylibrary". These beans are instantiated a using a @Configuration class that does a @ComponentScan, exactly like the example below:
@Configuration
@ComponentScan(basePackages = {MyLibrary.BASE_PACKAGE})
public class MyAppConfig {
}
interface MyLibrary {
String BASE_PACKAGE = "com.mycompany.mylibrary";
}
This setup causes a bunch of warnings saying "Could not autowire. No beans of '*' type found." for every bean inside the package "com.mycompany.mylibrary", even though they are correctly instantiated at runtime.
If I use change my @Configuration class to use the literal String as the name of the package (instead of a variable), the warnings go away.
@Configuration
@ComponentScan(basePackages = {"com.mycompany.mylibrary"})
public class MyAppConfig {
}
Is there a way to inform intellij that my constant MyLibrary.BASE_PACKAGE translates to the exact same as "com.mycompany.mylibrary"?
--------------------------------------
IntelliJ IDEA 2018.3.1 (Ultimate Edition)
Build #IU-183.4588.61, built on December 4, 2018
Please sign in to leave a comment.
Hello,
Could you please provide sample project example for investigation? It seems to work fine with test projects on my side.
Hi Yaroslav,
Here is a link to a sample project reproducing the issue.
https://github.com/marcel-ribeiro/IntelliJ-ticket-1905494
The README file should provide all the information needed but feel free to reach out in case you have any additional questions.
Thanks,
Marcel Ribeiro
Marcel,
Thanks for the example!
I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-204460
Please follow it for updates.