:建立項目工程spring
新建project瀏覽器
這裏選擇gradlespringboot
直接nextapp
繼續nextfetch
最後點擊finishgradle
二:建立Eureka服務中心spa
選擇第一步中建立的項目,右鍵選擇new--->module.net
選擇Spring Initializr,而後nextcode
這裏輸入Group、Artifact,並選擇Gradle Project,而後nextserver
選擇Eureka Server,而後點擊next
輸入module name而後finish
我這裏把幾個都勾上了,而後OK
三:代碼
代碼很簡單,只須要在springboot工程的啓動application類上加一個@EnableEurekaServer註解就好了,具體以下:
1 package com.cloud.microservice.demo.eurekaserver; 2
3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6
7 @EnableEurekaServer 8 @SpringBootApplication 9 public class EurekaServerApplication { 10
11 public static void main(String[] args) { 12 SpringApplication.run(EurekaServerApplication.class, args); 13 } 14 }
eureka server的配置文件appication.yml:
1 server: 2 port: 9090
3
4 eureka: 5 instance: 6 hostname: localhost 7 client: 8 registerWithEureka: false
9 fetchRegistry: false
10 serviceUrl: 11 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
啓動工程,打開瀏覽器訪問: http://localhost:9090,界面以下: