我正在学习spring boot eureka进行注册和发现。基本上,我有一个非常简单的spring boot应用程序(MyApp),它从db检索数据并将其显示为json,并且工作正常。现在,我创建了一个具有以下依赖项的spring boot项目(eureka-server):
<?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 https://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.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>eu.eureka.server</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud-services.version>2.1.4.RELEASE</spring-cloud-services.version>
<spring-cloud.version>Hoxton.RC1</spring-cloud.version>
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>io.pivotal.spring.cloud</groupId> -->
<!-- <artifactId>spring-cloud-services-starter-service-registry</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.springframework.cloud</groupId> -->
<!-- <artifactId>spring-cloud-starter-netflix-eureka-client</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>${spring-cloud-services.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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
我的尤里卡服务器的应用程序属性如下:
server.port=9092
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
[项目启动时,为了访问eureka服务器仪表板,我必须输入用户名:user和pwd,作为d94653bc-e831-461c-936b-556770bf1ae0,这是在我使用命令mvn spring-boot启动eureka-server时生成的:run并且我能够登录和访问仪表板:
问题是,当我尝试使用application.properties将我以前的应用程序(MyApp)注册到eureka服务器时,如下所示:
server.port=9090
eureka.client.serviceUrl.defaultZone=http://user:d94653bc-e831-461c-936b-556770bf1ae0:localhost:9092
该应用程序带有以下注释:
@SpringBootApplication
@EnableDiscoveryClient
public class MyAppApplication {
当我启动MyApp项目时,显示以下错误:
2019-10-29 13:23:11.867 ERROR 8512 --- [ restartedMain] c.n.d.s.r.aws.ConfigClusterResolver : Cannot resolve to any endpoints from provided configuration: {defaultZone=[http://user:d94653bc-e831-461c-936b-556770bf1ae0:localhost:9092/]}
如果我将这两个配置添加到MyApp项目的application.properties中,则:
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
当我启动MyApp项目但该项目未注册到eureka服务器仪表板时,没有显示错误。
知道我在这里想念什么吗?
请注意,我正在笔记本电脑上运行两个项目。
我怀疑错误提供了defaultURL。在本地主机之前,将“:”替换为“ @”
ex: http://user:d94653bc-e831-461c-936b-556770bf1ae0@localhost:9092