SpringCloud 运行Eureka Server启动成功但是一直不能加载Eureka Server的Home首页

今天遇到了一个很有意思的问题,运行Eureka Server启动成功但是一直不能加载Eureka Server的Home首页后台日志打印也没有报错,显示正常
build.gradle文件配置如下

buildscript {
	ext {
		springBootVersion = '2.0.0.RELEASE'
	}
	repositories {
		maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
	}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.weather.spring.cloud'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
	maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
	mavenCentral()
}

ext {
	springCloudVersion = 'Finchley.SR2'
}

dependencies {
	implementation('org.springframework.boot:spring-boot-starter-web')
	// Eureka Server
	compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

application.yml文件配置如下
 

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

日志如下

访问Eureka首页一直显示“Whitelabel Error Page”,然后通过google发现很多人都出现了这种问题
https://github.com/spring-cloud/spring-cloud-netflix/issues/2396
不过遗憾的是通过上面的方法也没解决问题,于是去到官网发现Eureka server Home 页是使freemarker编写所以猜想会不会需要引入freemarker的相关依赖于是在build.gradle文件配置中添加了freemarker的相关依赖

compile group: 'org.springframework.boot', name: 'spring-boot-starter-freemarker', version: '2.1.0.RELEASE'

application.yml文件中添加

spring:
  freemarker:
    template-loader-path: classpath:/templates/
    prefer-file-system-access: false

重新编译、运行后进行访问,Home页加载成功

发布了21 篇原创文章 · 获赞 8 · 访问量 40万+

猜你喜欢

转载自blog.csdn.net/qq_31150503/article/details/86079433