Create a springboot project pom.xml file as follows
4.0.0
<groupId>com</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
</plugin>
</plugins>
</build>
复制代码
On startup class annotate @EnableEurekaServer modify the configuration file as follows
Here peer1 and peer2 Modify the host file, and then add on the line, the equivalent server addressThen to the root directory of the project into cmd execute mvn clean package this time will appear in the target directory of the project a jar
And then proceeds to enter the target directory cmd Run java -jar eureka-server-0.0.1-SNAPASHOT.jar --spring.profiles.active = peer1 then command to open a window, also enter cmd in the target directory, execute command java -jar eureka-server-0.0.1-SNAPASHOT.jar --spring.profiles.active = peer2 this point your browser to localhost: 8760 and localhost: 8761 on itThen create two springboot project is almost the same, is to visit the port has changed as follows pom.xml
4.0.0
<groupId>com</groupId>
<artifactId>eureka-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-client</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
复制代码
Plus @EnableEurekaClient comment on the boot and then configure the following types of documents
Is not the same as the port number and then start two projects, you can find two items are registered to the 8760 and 8761 above, and in the two projects are coupled with this method, after testing easyFinally, create a boot project to test the pom.xml as follows
4.0.0 com eureka-client-1 0.0.1-SNAPSHOT eureka-client-1 Demo project for Spring Boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
复制代码
Start classes are as follows
In a new controller
Profiles
And then start the five projects, the browser visit http: // localhost:? 8763 / test name = Joe Smith returned data will be requested address, refresh a few times you will find the requested service is not the same