赞
踩
JDK1.11
SpringCloud GreenWich.SR1
SpringBoot 2.1.4 RELEASE
填写maven的GA信息并选择java版本
勾选Eureka模块
(可选操作,如果使用的是jdk1.8,则可以不导入以下依赖,jdk8以上版本会出现缺少以下依赖的问题)
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>activation</artifactId>
- <version>1.1.1</version>
- </dependency>
此时工程的pom文件如下
- <?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>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.4.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.springcloud</groupId>
- <artifactId>eureka-cluster</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>eureka-cluster</name>
- <description>Demo project for Spring Boot</description>
-
- <properties>
- <java.version>1.8</java.version>
- <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
- </properties>
-
- <dependencies>
- <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>
-
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jaxb</groupId>
- <artifactId>jaxb-runtime</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>activation</artifactId>
- <version>1.1.1</version>
- </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>
-
本次测试创建了三个springboot工程,当然也可以使用多profile来运行三个实例
eureka01
#eureka01的配置信息 spring: application: name: eureka #spring应用名称我这里都使用的是eureka server: port: 7002 #应用端口 eureka: instance: hostname: eureka02.com #域名 可以修改hosts文件做域名映射 prefer-ip-address: false #如果开启了此配置会导致集群不可用 (关闭或者不配置) instance-id: eureka02 client: register-with-eureka: true #是否要将自己注册进去 fetch-registry: true #是否要被检索 #eureka的访问路径,集群节点寻找时的地址信息,只需要配置其他两个节点的信息 service-url: defaultZone: http://eureka01.com:7001/eureka/,http://eureka03.com:7003/eureka/
eureka02
spring: application: name: eureka server: port: 7002 eureka: instance: hostname: eureka02.com prefer-ip-address: false instance-id: eureka02 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://eureka01.com:7001/eureka/,http://eureka03.com:7003/eureka/
eureka03
spring: application: name: eureka server: port: 7003 eureka: instance: hostname: eureka03.com prefer-ip-address: false instance-id: eureka03 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://eureka01.com:7001/eureka/,http://eureka02.com:7002/eureka/
- package com.lscw.springcloud.eureka02;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
-
- @SpringBootApplication
- @EnableEurekaServer//开启Eureka服务
- public class SpringCloudEureka01App {
- public static void main(String[] args) {
- SpringApplication.run(SpringCloudEureka02App.class,args);
- }
- }
-
java.net.ConnectException: Connection refused: connect
如果出现以上错误,则是eureka在寻找其他节点,等三个节点都启动完毕即可
这是我们打开浏览器访问任意一个节点都可以看到其他两个节点的信息
看到以上信息则表示我们的集群配置成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。