【发布时间】:2016-03-21 18:43:34
【问题描述】:
我正在尝试编写一个简单的 Spring Boot 应用程序,它可以 (1) 向 Netflix Eureka 服务器注册,以及 (2) 查询 Eureka 服务器以检索其他注册服务的详细信息。
我的客户端类有一个 @Autowired 类型为 com.netflix.discovery.DiscoveryClient 的字段,用于与 Eureka 对话并查询它以了解其他服务。在我的主课上,我有注释@EnableDiscoveryClient:
@SpringBootApplication
@EnableDiscoveryClient
public class AppBootstrap {
public static void main(String[] args) {
SpringApplication.run(AppBootstrap.class, args);
}
}
在我的 src/main/resources 下的 application.yml 文件中,我有:
eureka:
instance:
lease-renewal-interval-in-seconds: 10
lease-expiration-duration-in-seconds: 20
prefer-ip-address: true
secure-port: 443
non-secure-port: 80
metadata-map:
instanceId: my-test-instance
client:
service-url:
defaultZone: http://localhost:9080/eureka/
registry-fetch-interval-seconds: 6
instance-info-replication-interval-seconds: 6
register-with-eureka: true
fetch-registry: true
heartbeat-executor-thread-pool-size: 5
eureka-service-url-poll-interval-seconds: 10
当我启动我的应用程序时,服务无法启动,引发异常,其根源在于:
原因:java.lang.AbstractMethodError: org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.getInstanceI d()Ljava/语言/字符串; 在 com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider.get(EurekaConfigBasedInstanceInfoProvider .java:53) 在 com.netflix.appinfo.ApplicationInfoManager.initComponent(ApplicationInfoManager.java:90) ... 25 更多
我不知道这里发生了什么。有任何想法吗?我相信即使我的 Eureka 配置不正确,该应用程序仍应启动,但它在启动时会崩溃。
其次,我是否使用了正确的 DiscoveryClient?理想情况下,我想让它通用,以便我可以将它与 Eureka、Consul 或 ZooKeeper 一起使用作为示例。我发现文档没有很好地说明使用这些 Spring Cloud / Netflix 发现组件时需要什么。
【问题讨论】:
-
您使用的
eureka-client版本与 Spring Cloud Netflix 不兼容。为避免此类问题,您应该使用 Spring Cloud 的依赖管理。 -
我对 Spring Cloud 依赖管理没有太多经验。 ..你能给我举个例子吗?
-
这取决于您使用的是 Maven 还是 Gradle。尝试在the documentation 中搜索
bom。
标签: java spring spring-boot discovery netflix-eureka