一、配置文件添加eureka相关配置:

eureka.client.serviceUrl.defaultZone = http\://192.168.1.176\:8761/eureka/
eureka.client.healthcheck.enabled = true 
#开启健康检查(需要spring-boot-starter-actuator依赖)
      
eureka.instance.preferIpAddress = true
# 将Instance ID设置成IP:端口的形式
eureka.instance.instance-id = ${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.statusPageUrlPath = ${server.context-path:${SERVER_CONTEXTPATH:}}${management.context-path:${MANAGEMENT_CONTEXTPATH:}}${endpoints.info.path:/manager/login/loginIn}
eureka.instance.healthCheckUrlPath = ${server.context-path:${SERVER_CONTEXTPATH:}}${management.context-path:${MANAGEMENT_CONTEXTPATH:}}${endpoints.health.path:/health}
# 续约更新时间间隔(默认30秒)
eureka.instance.lease-expiration-duration-in-seconds = 10 
# 续约到期时间(默认90秒):到期后自动注销注册(此时在服务端看不到该服务),然后重新注册服务
eureka.instance.lease-renewal-interval-in-seconds = 5

二、在pom.xml文件中引入eurekaClient依赖jar包

<!-- Spring Cloud Config Client -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-client</artifactId>
</dependency>
    

三、启动类添加eurekaClient的相关注解@EnableCasClient //cas client客户端

Logo

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

更多推荐