我正在遵循此tutorial在我的项目中实现微服务架构。
首先,我在项目中添加了以下依赖项:
</dependencies>
...
<dependency>
<!-- Spring Cloud starter -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<!-- Eureka service registration - CHANGED -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
此后,我向该项目添加了registrationServer类(如本教程中所述)并设置了我的配置。 我的注册服务器的配置仍然非常基本:
# Ignore JDBC Dependency
# This demo puts 3 applicatons in the same project so they all pick up the
# JDBC Depdendency, but this application doesn't need it.
spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
# Configure this Discovery Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself
registerWithEureka: false
fetchRegistry: false
server:
port: 8761 # HTTP (Tomcat) port
现在,据我所知,此时我应该能够访问http://localhost:8761并查看注册服务器跟踪的设置。 相反,我得到一个 Whitelabel错误页面,其中包含以下错误消息:
Error resolving template [eureka/status], template might not exist or might not be accessible by any of the configured Template Resolvers
注意::在添加Eureka之前,我的项目由一个REST应用程序组成,现在我想将其转换为微服务。 REST服务包含一个前端,该前端组织在项目目录中,如下所示:
src
- main
- resources
- templates
- index.html
- static
- built
- bundle.js
注意2:另外,我尝试禁用百里香模板,从而导致在尝试访问http://localhost:8761时出现404错误。
# Discovery Server Dashboard uses FreeMarker. Don't want Thymeleaf templates
spring:
thymeleaf:
enabled: false # Disable Thymeleaf
datasource:
type: org.springframework.jdbc.datasource.SimpleDriverDataSource
答案 0 :(得分:0)
如果您的项目已经使用Thymeleaf作为其模板引擎,则可能无法正确加载Eureka服务器的Freemarker模板。在这种情况下,必须手动配置模板加载器:
application.yml
spring:
freemarker:
template-loader-path: classpath:/templates/
prefer-file-system-access: false