intellij incorrectly saying no beans of type found for autowired repository

前端 未结 30 2933
北恋
北恋 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: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;
    }
    

提交回复
热议问题