spring-boot - 使用 Eureka 服务器时出现“Whitelabel 错误页面”
问题描述
我使用 SPRING INITIALIZR 创建了一个 Spring Cloud 项目。我的项目结构如下: 在此处输入图片描述
演示应用程序:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
应用程序属性:
server.port=8888
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=localhost:8888/eureka
spring.application.name=appName
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>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.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>
<spring-cloud.version>Greenwich.M3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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>
</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>
<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>
但是当我访问 localhost:8888 时,出现以下错误:
Whitelabel 错误页面 此应用程序没有针对 /error 的显式映射,因此您将其视为后备。
Sun Dec 02 11:23:36 CST 2018 出现意外错误(类型=未找到,状态=404)。没有可用的消息
我不知道为什么会发生这种情况。我该如何解决?
解决方案
至少最新版本的 SpringBoot 和 Cloud 需要这些配置才能出现 Eureka UI:
#in application.yml
spring:
freemarker:
template-loader-path: classpath:/templates/
prefer-file-system-access: false
或者
#in application.properties
spring.freemarker.template-loader-path= classpath:/templates/
spring.freemarker.prefer-file-system-access= false
推荐阅读
- python - 错误:unindent 不匹配任何外部缩进级别(制作 reddit 机器人)
- linux - RAM中的页表在哪里?
- c# - ASP.NET MVC 5 POST 复选框,用于使用 Ajax 的 onclick 控制器
- javascript - 如何在不同设备上连续显示固定数量的图像
- sql - 第一次简单的Oracle查询速度极慢,无法控制数据库?
- java - 如何从一个活动传递数据,然后在另一个活动的 recyclerview 中检索?
- typescript - 否定打字稿类型?
- clingo - Clingo 打印重复的答案?
- ruby-on-rails - React:使用强制查询字符串添加路由
- excel - 如何测试 Outlook 是否打开?