<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zlpay</groupId> <artifactId>zl-eureka</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>zl-eureka</name> <description>服務註冊與發現</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.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.SR1</spring-cloud.version> </properties> <dependencies> <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-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
#服務註冊中心實例的主機名 spring: application: name: zl-eureka #節點1 profiles: peer1 server: #端口 port: 5001 eureka: instance: hostname: peer1 client: #是否向服務註冊中心註冊本身 registerWithEureka: true #是否檢索服務 fetchRegistry: true serviceUrl: #服務註冊中心的配置內容,指定服務註冊中心的位置 defaultZone: http://peer2:5002/eureka/,http://peer3:5003/eureka/ --- spring: application: name: zl-eureka profiles: peer2 server: port: 5002 eureka: instance: hostname: peer2 client: #是否向服務註冊中心註冊本身 registerWithEureka: true #是否檢索服務 fetchRegistry: true serviceUrl: #服務註冊中心的配置內容,指定服務註冊中心的位置 defaultZone: http://peer1:5001/eureka/,http://peer3:5003/eureka/ --- spring: application: name: zl-eureka profiles: peer3 server: port: 5003 eureka: instance: hostname: peer3 client: #是否向服務註冊中心註冊本身 registerWithEureka: true #是否檢索服務 fetchRegistry: true serviceUrl: #服務註冊中心的配置內容,指定服務註冊中心的位置 defaultZone: http://peer1:5001/eureka/,http://peer2:5002/eureka/
@EnableEurekaServer @SpringBootApplication public class ZlEurekaApplication { public static void main(String[] args) { SpringApplication.run(ZlEurekaApplication.class, args); } }
首先配置hosts文件,追加如下內容:java
127.0.0.1 peer1 127.0.0.1 peer2 127.0.0.1 peer3
4.1 Eclipse啓動web
Run Configurations中運行3次啓動三個節點,profile值分別是peer一、peer二、peer3spring
4.2 Jar包啓動apache
先將項目打成jar包,而後使用jar命令:tomcat
java -jar zl-eureka-0.0.1.jar --spring.profiles.active=peer1app
java -jar zl-eureka-0.0.1.jar --spring.profiles.active=peer2maven
java -jar zl-eureka-0.0.1.jar --spring.profiles.active=peer3ide
4.3 war包啓動spring-boot
待續…fetch