分布式02Springcloudeureka注册发现使用搭建
compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-server"
compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
Application添加注解
@EnableDiscoveryClient(eureka 客户端)
@EnableEurekaServer(eureka 服务端)
application.properties
应用A添加
server.port=12000#端口eureka.instance.hostname=localhost #IPeureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:12000/eureka/, http://${eureka.instance.hostname}:12002/eureka/ #注册地址eureka.client.healthcheck.enabled=true #监控检查spring.application.name=eureka-server#应用名字
应用B添加
eureka.instance.hostname=localhostserver.port=12002eureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:12000/eureka/, http://${eureka.instance.hostname}:12002/eureka/eureka.client.healthcheck.enabled=truespring.application.name=eureka-api
eureka.client.service-url.defaultZone= 多个地址是为了高可用,也可以只指定一个服务。
启动A,B2个应用会看到
打开链接localhost:12000
会看到我们的服务已经组成在eureka上面了
以上是 分布式02Springcloudeureka注册发现使用搭建 的全部内容, 来源链接: utcz.com/z/514947.html