No found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:

后端 未结 13 807
时光说笑
时光说笑 2020-12-08 01:43

I am trying to write a SOAP service using Spring, however I receive a Dependency Injection issue. I\'m having problems using @Autowired through the Service like

相关标签:
13条回答
  • 2020-12-08 02:05

    You seems to be missing implementation for interface UserDao. If you look at the exception closely it says

    No qualifying bean of type [edu.java.spring.ws.dao.UserDao] found for dependency:

    The way @Autowired works is that it would automatically look for implementation of a dependency you inject via an interface. In this case since there is no valid implementation of interface UserDao you get the error.Ensure you have a valid implementation for this class and your error should go.

    Hope that helps.

    0 讨论(0)
  • 2020-12-08 02:05

    I missed to add

    @Controller("userBo") into UserBoImpl class.
    

    The solution for this is adding this controller into Impl class.

    0 讨论(0)
  • 2020-12-08 02:07

    Add repository annotation before your DAO Implementation Class. example:

    @Repository
    public class EmpDAOImpl extends BaseNamedParameterJdbcDaoSupportUAM 
    implements EmpDAO{ 
    }
    
    0 讨论(0)
  • 2020-12-08 02:08

    Could me multiple reason for this. But you want might forget to add as @Bean for component which you have did @Autowired.

    In my case, i have forgot to decorate with @Bean which causing this issue.

    0 讨论(0)
  • 2020-12-08 02:10

    Look at the exception:

    No qualifying bean of type [edu.java.spring.ws.dao.UserDao] found for dependency
    

    This means that there's no bean available to fulfill that dependency. Yes, you have an implementation of the interface, but you haven't created a bean for that implementation. You have two options:

    • Annotate UserDaoImpl with @Component or @Repository, and let the component scan do the work for you, exactly as you have done with UserService.
    • Add the bean manually to your xml file, the same you have done with UserBoImpl.

    Remember that if you create the bean explicitly you need to put the definition before the component scan. In this case the order is important.

    0 讨论(0)
  • 2020-12-08 02:11

    In my case, the application context is not loaded because I add @DataJpaTest annotation. When I change it to @SpringBootTest it works.

    @DataJpaTest only loads the JPA part of a Spring Boot application. In the JavaDoc:

    Annotation that can be used in combination with @RunWith(SpringRunner.class) for a typical JPA test. Can be used when a test focuses only on JPA components. Using this annotation will disable full auto-configuration and instead apply only configuration relevant to JPA tests.

    By default, tests annotated with @DataJpaTest will use an embedded in-memory database (replacing any explicit or usually auto-configured DataSource). The @AutoConfigureTestDatabase annotation can be used to override these settings. If you are looking to load your full application configuration, but use an embedded database, you should consider @SpringBootTest combined with @AutoConfigureTestDatabase rather than this annotation.

    0 讨论(0)
提交回复
热议问题