###spring-cloud Netflix 的主要模塊:java
本文章將學習Eureka服務器端。web
第一步:搭建項目,配置 pom.xmlspring
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.RELEASE</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <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> </dependencies>
第二步:配置 spring-boot application.propertise文件配置瀏覽器
## 服務器的項目的名稱 spring.application.name=spring-cloud-eureka-server ## 端口號 server.port=9090 ## Eureka服務器查看地址 management.server.servlet.context-path=http://localhost:${server.port} ## 取消服務器的自我註冊 eureka.client.register-with-eureka=false ## 不檢索服務 eureka.client.fetch-registry=false ## Eureka客戶端服務註冊地址 eureka.client.serviceUrl.defaultZone=${management.server.servlet.context-path}/eureka
第三步:啓動代碼服務器
@SpringBootApplication @EnableEurekaServer public class SpringCloudEurekaServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudEurekaServerApplication.class, args); } }
第四步:打開瀏覽器 訪問 http://localhost:9090 結果以下: app