Spring eureka - Ошибка при разрешении шаблона [eureka / status], шаблон может не существовать или быть недоступным - PullRequest
0 голосов
/ 13 мая 2019

Я следую этому учебнику , чтобы реализовать микросервисную архитектуру в моем проекте.

Сначала я добавил в свой проект следующие зависимости:

</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: Также я попытался отключить шаблон тимелина, который привел к ошибке 404 при попытке доступа к http://localhost:8761.

# Discovery Server Dashboard uses FreeMarker.  Don't want Thymeleaf templates
spring:
  thymeleaf:
    enabled: false     # Disable Thymeleaf 
  datasource:
    type: org.springframework.jdbc.datasource.SimpleDriverDataSource

1 Ответ

0 голосов
/ 14 мая 2019

Как указано в этой проблеме github:

Если ваш проект уже использует Thymeleaf в качестве механизма шаблонов, шаблоны Freemarker сервера Eureka могут загружаться неправильно.В этом случае необходимо настроить загрузчик шаблонов вручную:

application.yml

spring:
  freemarker:
    template-loader-path: classpath:/templates/
    prefer-file-system-access: false
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...