【发布时间】:2017-01-01 22:09:55
【问题描述】:
我有以下 Spring Boot 应用程序(使用 Eureka 和 Feign):
@SpringBootApplication
@EnableFeignClients
@EnableRabbit
@EnableDiscoveryClient
@EnableTransactionManagement(proxyTargetClass = true)
public class EventServiceApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(EventServiceApplication.class, args);
}
}
以及以下测试,用@SpringJpaTest 注释:
@RunWith(SpringRunner.class)
@DataJpaTest(showSql = true)
public class EventRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private EventRepository repository;
@Test
public void testPersist() {
this.entityManager.persist(new PhoneCall());
List<Event> list = this.repository.findAll();
assertEquals(1, list.size());
}
}
在运行测试时,我收到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.netflix.discovery.EurekaClient] found for dependency [com.netflix.discovery.EurekaClient]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
完整的堆栈跟踪here
有没有办法解决这个问题?我已经看到它是由@EnableFeignClients 和@EnableDiscoveryClient 注释引起的。
【问题讨论】:
标签: spring spring-boot spring-data-jpa spring-test