无法将服务注册为 Eureka Client [英] Not able to register a service as Eureka Client
问题描述
我正在尝试将微服务注册为 Eureka 客户端以发现其他微服务,但是,我按照教程进行操作,但 Eureka 服务器中没有显示任何内容.以下是代码片段:
I'm trying to register a Microservice as Eureka Client in order to discover other Microservices, however, I follow the tutorial but nothing shows up in the Eureka Server. Below are code snippets:
我的
demo
应用程序:一个在localhost:9001
上运行的 spring boot 应用程序,我希望它成为一个 Eureka 客户端,即,将自己注册为一个实例并同时具有发现其他实例的能力(我使用了通用的@EnableDiscoveryClient
注释并且 Spring Netflix Eureka 在类路径上):
My
demo
application: a spring boot application running onlocalhost:9001
, I want it become a Eureka Client, i.e., register itself as an instance and meanwhile has ability to discover other instances (I used the generic@EnableDiscoveryClient
annotation and Spring Netflix Eureka is on the classpath):
@RestController
@SpringBootApplication
@EnableDiscoveryClient
public class DemoApplication {
@RequestMapping("/")
String home() {
return "This is a Demo project";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
application.yml:
application.yml:
server:
port: 9001
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Eureka Server 应该没有问题,因为我在 localhost:8080
上运行的另一个 Miscroservice 已在服务器中成功注册.以防万一这里是 Eureka 服务器的 application.yml:
The Eureka Server should be no problem since I have another Miscroservice running on localhost:8080
is successfully registered in the server. Just in case here is the application.yml for the Eureka Server:
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
有人看到这里有什么问题吗?
Anyone see any problems here?
推荐答案
重要的是选择正确的导入.我失去了几个小时才意识到:
The important thing is select the right import. I lost hours before realizing that:
这是裸依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
这是大多数情况下需要的入门包依赖项:
This is the starter pack dependency wanted in most case:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
如果导入裸依赖,不会显示错误或日志,但服务不会注册到 Eureka 服务器.
If you import the bare dependency, no errors or logs will show up but the service will not register to Eureka server.
最重要的是,请务必仔细检查依赖项:也许您需要 Spring boot 组件的启动包"依赖项.
这篇关于无法将服务注册为 Eureka Client的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!