1.添加依賴jar包
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!-- 修改後立即生效,熱部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
2.編寫application.yml
server:
port: 2001
context-path: /
eureka:
instance:
# 單機 hostname: localhost #eureka註冊中心實例名稱
hostname: eureka2001.java1234.com # 集羣
client:
register-with-eureka: false #false 由於該應用爲註冊中心,所以設置爲false,代表不向註冊中心註冊自己。
fetch-registry: false #false 由於註冊中心的職責就是維護服務實例,它並不需要去檢索服務,所以也設置爲false
service-url:
defaultZone: http://eureka2002.java1234.com:2002/eureka/,http://eureka2003.java1234.com:2003/eureka/ # 集羣
#單機defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #設置與Eureka註冊中心交互的地址,查詢服務和註冊服務用到 #設置與Eureka註冊中心交互的地址,查詢服務和註冊服務用到
3.編寫啓動類:
package com.java1234;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication_2001 {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication_2001.class, args);
}
}