gradle 引入包spring
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'api
Application添加注解app
@EnableDiscoveryClient(eureka 客户端)
@EnableEurekaServer(eureka 服务端)gradle
application.propertiesurl
应用A添加spa
server.port=12000#端口 eureka.instance.hostname=localhost #IP eureka.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添加server
eureka.instance.hostname=localhost server.port=12002 eureka.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-api
eureka.client.service-url.defaultZone= 多个地址是为了高可用,也能够只指定一个服务。blog
启动A,B2个应用会看到io
打开连接localhost:12000监控
会看到咱们的服务已经组成在eureka上面了