從新再過一遍SpringCloud,這裏算是筆記,源碼會傳到git上。git
這裏使用Spring Initializr方式建立工程 web
頁面上輸入http://localhost:8080/ 能夠看到以下spring
把applications.properties改成使用applications.yml。 server也是client,能夠把本身註冊進去。app
eureka: client: service-url: #這裏底層是Map,因此要輸入鍵值對形式 defaultZone: http://localhost:8080/eureka/
如上面applications.yml編寫,能夠看到運行後以下: spring-boot
像上面的狀況,做爲server,不讓註冊的話,能夠使用 register-with-eureka: false
url
eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ # 自定義連接 # instance: # hostname: clientName spring: application: name: client
修改eureka端口號爲8761,啓動client,能夠看到註冊到eureka code
這裏模擬一下三個eureka互相調用的狀況,端口號分別爲8761 8762 8763.server
逐個修改aplications.yml中兩兩互相調用blog
eurekaApplication1:get
eureka: client: service-url: defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/ spring: application: name: test
eurekaApplication2:
eureka: client: service-url: defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/ spring: application: name: test
eurekaApplication3:
eureka: client: service-url: defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ spring: application:
而後啓動client,頁面能夠看到:
其它兩個8762 8763頁面也是對應的.
這裏client雖然註冊到8761上,8762 8763都可註冊,可是避免一個掛了,就註冊不上了,能夠註冊多個eureka。