(一)註冊中心Eureka簡單操作
阿新 • • 發佈:2018-12-31
一、準備開發環境和開發工具
jdk1.8,idea開發工具,maven管理工具
二、新建一個maven專案(方便後續操作管理)
完成後刪除src目錄的所有東西
新建註冊中心專案
pom
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
application.properties配置
server.port=8000
eureka.instance.hostname=localhost
#是否開啟自己的註冊
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
EurekaApplication 啟動檔案主要是@EnableEurekaServer註釋
package com.eureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } }