intellij incorrectly saying no beans of type found for autowired repository

前端 未结 30 2918
北恋
北恋 2020-11-30 18:33

I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error

No beans?

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 19:08

    Sometimes you are required to indicate where @ComponentScan should scan for components. You can do so by passing the packages as parameter of this annotation, e.g:

    @ComponentScan(basePackages={"path.to.my.components","path.to.my.othercomponents"})
    

    However, as already mentioned, @SpringBootApplication annotation replaces @ComponentScan, hence in such cases you must do the same:

    @SpringBootApplication(scanBasePackages={"path.to.my.components","path.to.my.othercomponents"})
    

    At least in my case, Intellij stopped complaining.

提交回复
热议问题