Обновление до Spring Boot 2.2.2.RELEASE + Thymeleaf 3.0.11.RELEASE, тимелиф / макет перестал работать - PullRequest
3 голосов
/ 14 января 2020

После миграции Spring-Boot с 1.5.3.RELEASE на 2.2.2.RELEASE Thymeleaf перестал работать.

pom. xml

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

...

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

Я следовал Thymeleaf 3 руководство по миграции + чтение выпуск Spring-Boot , но безуспешно ...

Фрагмент шаблона (Thymeleaf 3.0 layout:decorate)

<!DOCTYPE html>
<html th:lang="${#locale}" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="https://www.thymeleaf.org"
    xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
    xmlns:layout="https://www.ultraq.net.nz/thymeleaf/layout"
    layout:decorate="layout">
<head>
<title></title>
</head>
<body>
    <div layout:fragment="content">

http://localhost/index Сравнение путей:

Фрагмент кода (1.5.3.RELEASE)

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

    <title>APLLICATION</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'/><![endif]-->
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
    <meta name="description" content="Application description" />
    <meta name="fragment" content="text" />

    <link rel="stylesheet" href="css/vendor/bootstrap.min.css" />
    <link rel="stylesheet" href="css/vendor/jquery-ui.min.css" />
    ...

Фрагмент кода (2.2.2.RELEASE)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:layout="https://www.ultraq.net.nz/thymeleaf/layout"
    layout:decorate="layout">
<head>
<title></title>
</head>
<body>
    <div layout:fragment="content">
...

Любая помощь приветствуется. Спасибо

РЕДАКТИРОВАТЬ:

@ Marged, модели установлены:

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        ...
    }

}

Контекст-путь по умолчанию (/)

@SpringBootApplication(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@EnableConfigurationProperties({ AppConfig.class })
@EnableScheduling
@EnableJpaRepositories
@EnableAutoConfiguration
@ComponentScan("foo.bar")
public class MainApplication {

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

1 Ответ

4 голосов
/ 20 февраля 2020

Ваша проблема, похоже, связана с Диалектом Thymeleaf Layout (см. # 4). Spring-Boot 1.5.3.RELEASE поддерживает его из коробки, а 2.2.2.RELEASE - нет. Это даже указано в документации диалекта :

Диалект макета уже включен как часть начального пакета Thymeleaf в Spring Boot 1.x, но был удален в Spring Boot 2, отсюда и дополнительный шаг настройки для пользователей Spring Boot 2.

Следующие шаги установки из приведенной выше ссылки должны быть полезны, например:

  • Добавить зависимость maven:
<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>2.4.1</version>
</dependency>
  • Добавьте Extra @Bean к вашей конфигурации:
@Bean
public LayoutDialect layoutDialect() {
    return new LayoutDialect();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...