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

后端 未结 13 813
时光说笑
时光说笑 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: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.

提交回复
热议问题