1、概述
Eureka Client,即服务提供方或者服务消费方,是通过注册中心向外提供服务的程序,或是通过注册中心获取服务的程序。
2、项目构建
2.1 pom.xml
在pom.xml中添加Eureka Client相关依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
2.2 启动类
启动类添加注解@EnableEurekaClient
@EnableEurekaClient
@SpringBootApplication
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
2.3 application.yml配置
在application.yml中添加Eureka Client的配置
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
healthcheck:
enabled: true
instance:
prefer-ip-address: true
ip-address: 127.0.0.1
2.4 Eureka Server页面
访问localhost:8761/eureka,查看Eureka Client注册状态
至此,Eureka Client项目创建完成,是不是也是so easy!