父项目pom:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.cloud.parent</groupId>
<artifactId>com-cloud-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.cloud.parent</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<modules>
<module>com-eureka-server</module>
<module>com-eureka-client001</module>
<module>com-eureka-client002</module>
<module>com-eureka-server001</module>
<module>com-eureka-server002</module>
</modules>
</project>
client端pom:
<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">
<parent>
<artifactId>com-cloud-parent</artifactId>
<groupId>com.cloud.parent</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>com-eureka-client002</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
yml配置:
application:
name: com-eureka-client002
server:
port: 8001
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:7000/eureka/,http://127.0.0.1:7001/eureka/,http://127.0.0.1:7002/eureka/
registerWithEureka: true
fetchRegistry: true
# server:
# enableSelfPreservation: true #关闭自我保护模式(缺省为打开)
# eviction-interval-timer-in-ms: 5000 #续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms),测试环境修改小点
启动类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* Created by lj on 2020/4/25.
*/
@EnableDiscoveryClient
@SpringBootApplication
public class EurekaClient002Application {
public static void main(String[] args) {
SpringApplication.run(EurekaClient002Application.class,args);
}
}