博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring cloud之eureka服务注册
阅读量:4171 次
发布时间:2019-05-26

本文共 2691 字,大约阅读时间需要 8 分钟。

上一章搭建了eureka注册中心,这章就写搭建一个client服务注册到注册中心上去。

pom文件:

4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
com.zsy.cloud
eureka-client
1.0.0
jar
eureka-client
1.8
Greenwich.M3
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false

 

yml文件:

###服务启动端口号server:  port: 8082###服务名称(服务注册到eureka名称)spring:  application:    name: zsy-app###服务注册到eureka地址eureka:  client:    service-url:      defaultZone: http://localhost:8081/eureka    ###册自己到注册中心    register-with-eureka: true    ###是否需要从eureka上获取注册信息    fetch-registry: true  # 心跳检测检测与续约时间  # 测试时将值设置设置小些,保证服务关闭后注册中心能及时踢出服务  instance:    ###Eureka客户端向服务端发送心跳的时间间隔,单位为秒(客户端告诉服务端自己会按照该规则)    lease-renewal-interval-in-seconds: 1    ####Eureka服务端在收到最后一次心跳之后等待的时间上限,单位为秒,超过则剔除(客户端告诉服务端按照此规则等待自己)    lease-expiration-duration-in-seconds: 2

 

启动类:

package com.zsy.cloud.eureka_client;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClientpublic class ClientApplication {		public static void main(String[] args) {		SpringApplication.run(ClientApplication.class, args);	}}

加入@EnableEurekaClient注解使其成为eureka的client

 

再次访问eureka的管理后台:

发现client已成功注册进来。

转载地址:http://gpbai.baihongyu.com/

你可能感兴趣的文章
拿走不谢!固件逆向分析过程中的工具和技巧(上)
查看>>
整理网络安全措施的5个小技巧
查看>>
入侵win10(下)--渗透系统
查看>>
烦请解释一下“驱动表”的概念
查看>>
IPAide(IP助手) v1.01
查看>>
Oracle 11g RAC SCAN basics
查看>>
ASM appears to be running, but connect via sqlplus, says idle instance.??
查看>>
Oracle EBS R12 - Steps and Issues/Resolutions during R12.1.1 to R12.1.3 Upgration
查看>>
跳过17:30,跳过瑞星定时扫描
查看>>
自动订饭
查看>>
Dos下命令运行带有包名的Java类
查看>>
Tomcat6数据源配置
查看>>
xmove.pl
查看>>
Excel简单五子棋
查看>>
Java之synchronized小例
查看>>
jstl之set与out小例
查看>>
apploc.bat
查看>>
乱撞解决word只能以安全模式启动
查看>>
Oracle外部表小例
查看>>
在VS.NET的VC++中运行控制台程序后暂停
查看>>