【发布时间】:2017-05-25 02:37:08
【问题描述】:
我正在尝试在 Spring boot 1.5.0.RC1 中使用新的 @JdbcTest 注释。
我的应用程序使用 Eureka 发现,即我有
compile('org.springframework.cloud:spring-cloud-starter-eureka')
在我的 build.gradle 和
@EnableDiscoveryClient
在我的主要 Spring Boot 类中
当我尝试使用 @JdbcTest 测试基于 JdbcTemplate 的 DAO 时,我收到此错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method eurekaHealthIndicator in org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration$EurekaHealthIndicatorConfiguration required a bean of type 'com.netflix.discovery.EurekaClient' that could not be found.
Action:
Consider defining a bean of type 'com.netflix.discovery.EurekaClient' in your configuration.
看起来自动配置正在加载 Eureka 配置的一部分,而它应该只加载与 JDBC 相关的 bean。
如果我添加
@TestPropertySource(properties={"eureka.client.enabled=false"})
测试问题消失了,但我认为@JdbcTest 应该已经确保只加载了相关的bean。
我是否遗漏了什么,或者这是新的@JdbcTest 或 Spring Cloud Eureka 的问题?
【问题讨论】:
-
尝试将这些选项添加到您的测试道具中:
eureka.client.register-with-eureka=false和eureka.client.fetch-registry=false和endpoints.health.enabled=false -
正如我所说,当我添加 eureka.client.enabled=false 时它会起作用。但是@JdbcTest 的想法是它只关心应用程序的 JDBC 层。我不应该开始弄清楚我的整个应用程序中的哪些额外依赖项会导致问题以及如何关闭它们。
标签: spring-boot spring-cloud-netflix