1新建eureka-client模块,

 

pom.xml依赖如下

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2启动类添加@EnableEurekaClient(注解表明是一个Eureka客户端)

package com.example.springcloudeurekaclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;


@SpringBootApplication
@EnableEurekaClient
public class SpringcloudEurekaClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudEurekaClientApplication.class, args);
    }

}

3在配置文件application.yml中添加(Eureka客户端的配置)

server:
  port: 8102 #运行端口号
spring:
  application:
    name: springcloud-eureka-client #服务名称
eureka:
  client:
    register-with-eureka: true #注册到Eureka的注册中心
    fetch-registry: true #获取注册实例列表
    service-url:
      defaultZone: http://localhost:8081/eureka/ #配置注册中心地址

4 查看Eureka注册中心

http://localhost:8001/发现Eureka客户端已经成功注册

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐