intellij incorrectly saying no beans of type found for autowired repository

前端 未结 30 2762
北恋
北恋 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

    I just had to use @EnableAutoConfiguration to address it, however this error had no functional impact.

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

    I had a similar problem in my application. When I added annotations incorrect highliting dissapeared.

    @ContextConfiguration(classes = {...})
    
    0 讨论(0)
  • 2020-11-30 19:11

    Check if you missed @Service annotation in your service class, that was the case for me.

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

    And one last piece of important information - add the ComponentScan so that the app knows about the things it needs to wire. This is not relevant in the case of this question. However if no @autowiring is being performed at all then this is likely your solution.

    @Configuration
    @ComponentScan(basePackages = {
        "some_package",
    })
    public class someService {
    
    0 讨论(0)
  • 2020-11-30 19:13

    Surprisingly, A Feign oriented project that successfully ran with Eclipse could not run in InteliJ. When started the application, InteliJ complained about the Feign client I tried to inject to the serviceImpl layer saying: field personRestClient (my Feign client) in ... required a bean of type ... that could not be found. Consider defining a bean of type '....' in your configuration.

    I wasted a long time trying to understand what is wrong. I found a solution (for InteliJ) which I do not completely understand:

    1. Alt Shift F10 (or run menu)
    2. Select 'Edit configuration'
    3. In configuration window, Check the checkbox 'include dependencies with "Provided" scope'
    4. Run your application

    Or choose Eclipse :)

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

    Check if the package of your bean is written correctly

    //Check if this is written right 
    package com.package1.package2.package3
    
    
    import ...
    
    @Service
    class ServiceX {
    
      ...
    
    }
    
    0 讨论(0)
提交回复
热议问题