Spring Boot Eureka服务器仪表板错误

3

我一直在尝试使用Spring Boot和Netflix OSS学习微服务开发。

我已经卡在Eureka仪表板错误上两天了,但似乎无法解决。请帮忙。 我只有一个Discovery Client实例,而服务器处于独立模式 这是仪表板的样子

以下是服务器主类:

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer

public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }
}

配置文件 application.yml

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
     defaultZone: ${eureka.instance.hostname}:${server.port}/eureka/
    server:
      waitTimeInMsWhenSyncEmpty: 0

bootstrap.yml

spring:
  application:
    name: 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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>EurekaApplication</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</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>
                <version>Brixton.RC1</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-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

你使用Spring Boot的父POM而不是Spring Cloud的POM,有什么原因吗? - Aritz
@XtremeBiker 我使用了Spring Initializr创建项目,这可能是问题的根源吗? - xoloh_foundry
不知道,但我会尝试一下。另外,您正在使用目前处于测试阶段的Brixton版本。您可以尝试使用Angel版本。无论如何,向Spring团队报告任何与Brixton相关的问题都是好的。 - Aritz
@XtremeBiker,感谢您指引我找到了答案。Angel.SR6 抛出了 Brixton 没有抛出的异常,这让我锁定了罪魁祸首。我的回答如下。 - xoloh_foundry
2个回答

0

如果您使用的是发布版本,则无需将spring-milestone添加为依赖项。它仅在您使用M版本时使用。有关更多详细信息,请参阅Spring Boot官方文档。您的代码看起来很好,应该可以工作。请指定您遇到的错误。这是我正在使用的pom.xml和.yml文件,可以正常工作:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.samples.service.service microservice-demo 1.1.0.RELEASE jar

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Brixton.RELEASE</version>
</parent>

<properties>
    <!-- Stand-alone RESTFul application for testing only -->
    <start-class>io.pivotal.microservices.services.Main</start-class>
</properties>

<dependencies>
    <dependency>
        <!-- Setup Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring MVC & REST, use Embedded Tomcat -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring Data common components -->
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
    </dependency>

    <dependency>
        <!-- Testing starter -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring Data JPA Repository support -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <!-- In-memory database for testing/demos -->
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
    </dependency>

    <dependency>
        <!-- Spring Cloud starter -->
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>

    <dependency>
        <!-- Eureka service registration -->
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

配置此发现服务器

eureka: instance: hostname: localhost client: # 不是客户端,不要向自己注册 registerWithEureka: false fetchRegistry: false

  server:
  port: 1111   # HTTP (Tomcat) port

# Discovery Server Dashboard uses FreeMarker.  Don't want Thymeleaf        templates
spring:
  thymeleaf:
    enabled: false     # Disable Thymeleaf 

0
问题出在我的application.yml文件上,serviceUrl属性值有一个拼写错误。我忘记在eureka.instance.hostname之前包含http://了。
这是已修复的yaml文件。
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
     defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    server:
      waitTimeInMsWhenSyncEmpty: 0

这从来不是Brixton.RC1的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接