集成Eureka-server和Eureka-cliet以及遇到的各种问题总结
1.Springboot和Springclould版本问题?第一种情况:启动报错,启动不了aplication,版本有问题不兼容第二种情况:正常启动,各种配置没有问题,注册服务中心找不到,比如服务端配置:server.port=8888eureka.instance.hostname=localhost#代表不向注册中心注册自己eureka.client.register-wi...
·
环境配置Eureka-server
application.properties配置:
server.port=8761
eureka.instance.hostname=localhost
#代表不向注册中心注册自己
eureka.client.register-with-eureka=false
#维护服务实例,不需要检索服务
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
pom.xml文件
<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.unistrong</groupId>
<artifactId>eureka-servser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>eureka-servser</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!-- RELEASE -->
<version>Finchley.RELEASE</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
类配置:
@SpringBootApplication
@EnableEurekaServer
public class EurekaServserApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServserApplication.class, args);
}
}
Eureka-client:
application.properties配置:
spring.application.name=eureka-server
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
pom.xml
<?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.unistrong</groupId>
<artifactId>eureka-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>eureka-client</name>
<description>微服务构建</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.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>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--一定要加入这个依赖 -->
<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>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!-- RELEASE -->
<version>Finchley.RELEASE</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>
类的配置:
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
1.Springboot和Springclould版本问题?
第一种情况:启动报错,启动不了aplication,版本有问题不兼容
第二种情况:正常启动,各种配置没有问题,注册服务中心找不到,比如服务端配置:
server.port=8888
eureka.instance.hostname=localhost
#代表不向注册中心注册自己
eureka.client.register-with-eureka=false
#维护服务实例,不需要检索服务
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
----------------------------------------------------------------------------------------
maven依赖
<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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!-- 重点:Finchley.RELEASE是兼容的,下面定义的版本和springboot是不兼容的 -->
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
启动项目:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
内心是崩溃的,网上各种找都是说版本不一致,启动就会报错,我就坚信了,于是弄了几天都没找到问题,springclould官方给出的springboot和springcloud给出的版本也是这样的,,但是版本依然是有问题,需要换版本。
2.Eureka-clinet配置没有什么问题,和别人使用的配置是一样的,但是Finchley.RELEASE版本启动的客户端的时候是这样的
控制台显示没有成功的信息
Registered instance EUREKA-SERVER/edz-PC:eureka-server:9090 with status DOWN (replication=false)
控制台信息显示成功的信息
DiscoveryClient_EUREKA-SERVER/edz-PC:eureka-server:9090 - registration status: 204
使用Finchley.RELEASE版本一定要引入web
<!--一定要加入这个依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
更多推荐
已为社区贡献2条内容
所有评论(0)