intellij incorrectly saying no beans of type found for autowired repository

前端 未结 30 2764
北恋
北恋 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 18:55

    I always solve this problem doing de following.. Settings>Inspections>Spring Core>Code than you shift from error to warning the severity option

    0 讨论(0)
  • 2020-11-30 18:56

    This seems to still be a bug in the latest IntelliJ and has to do with a possible caching issue?

    If you add the @Repository annotation as mk321 mentioned above, save, then remove the annotation and save again, this fixes the problem.

    0 讨论(0)
  • 2020-11-30 18:57

    For me the solution was to place @EnableAutoConfiguration in the Application class under the @SpringBootApplication its going to underline it because its redundant. Delete it and voila all you warnings regarding missing beans are vanished! Silly Spring...

    0 讨论(0)
  • 2020-11-30 18:57

    simple you have to do 2 steps

    1. add hibernate-core dependency
    2. change @Autowired to @Resource.
    ==>> change @Autowired to  @Resource
    
    0 讨论(0)
  • 2020-11-30 19:01

    My version of IntelliJ IDEA Ultimate (2016.3.4 Build 163) seems to support this. The trick is that you need to have enabled the Spring Data plugin.

    0 讨论(0)
  • 2020-11-30 19:01

    Use @EnableAutoConfiguration annotation with @Component at class level. It will resolve this problem.

    For example:

    @Component
    @EnableAutoConfiguration  
    public class ItemDataInitializer  {
    
        @Autowired
        private ItemReactiveRepository itemReactiveRepository;
    
        @Autowired
        private MongoOperations mongoOperations;
    }
    
    0 讨论(0)
提交回复
热议问题