天天看点

搭建eureka client

记一次完成的搭建eureka client

1.新建client 项目

搭建eureka client
搭建eureka client

此处选择eureka discovery,点击next 直到finish。

2.erueka server 配置

在启动类上添加如下配置:

@SpringBootApplication :springboot启动注解
@EnableDiscoveryClient:开启eureka服务端      
搭建eureka client

在application.yml 中配置端口并配置注册地址:

搭建eureka client
搭建eureka client

启动项目,此时如果springboot版本是2.1.3可能会报错,原因是因为eureka client包没有集成

spring-boot-starter-web包,可以手动添加到pom 中再次启动即可。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
      
搭建eureka client

打开eureka ui 面板,可以查看注册的服务信息:

搭建eureka client

注:

标红区域在application.yml做如下配置即可:

搭建eureka client
instance:
  instance-id: ${spring.cloud.client.ip-address}:${server.port}      
spring:
  application:
    name: client      

知识点:

搭建eureka client

鼠标虚浮箭头处,左下角显示的地址不同如何解决?

搭建eureka client

添加如下配置即可

prefer-ip-address: true      

继续阅读