迁移到 Thymeleaf 3 后,Thymeleaf 停止解析布局模板 [英] Thymeleaf stopped resolving layout templates after migrating to Thymeleaf 3

查看:62
本文介绍了迁移到 Thymeleaf 3 后,Thymeleaf 停止解析布局模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 1.5.7 版中有一个简单的 Spring Boot 应用程序,我正在尝试将其迁移到 2.0.0 版.我快完成了,但还缺少最后一块,那就是 Thymeleaf.

在旧版本中一切正常,但迁移后,Spring Boot 停止解析任何模板(页面和电子邮件).

我有所有模板 src/main/resources/templates.另外,我在 src/main/resources/templates/layout 中有一个名为 default 的布局,如下所示:

<head th:replace="fragments/header::head"></head><身体><div id="页面"><nav class="navigation" th:replace="fragments/navigation"></nav><div class="容器"><div layout:fragment="container"></div>

</html>

我的页面像这样链接到这个布局:

<html lang="zh-cn"xmlns:th="http://www.thymeleaf.org"xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"布局:装饰=布局/默认"><身体><div layout:fragment="container">...</html>

src/main/resources/templeas/fragments

中本地化的导航片段

在 Spring Boot 2 中,呈现登录页面但未应用布局(因此缺少导航栏和样式).2.0.0 版有什么变化吗?我在官方文档或迁移指南中没有找到任何解决方案.

正如答案中所建议的,它是由迁移到 Thymeleaf 3 引起的.我更新了我的问题,并进行了一些反映迁移指南的更改,但代码仍未注入布局.

我也试过 layout:data-layout-decorate=~{layout/default} 和 layout:data-layout-decorate=~{layout/default.html}

我通过手动添加百里香方言依赖使其工作:

compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')

但我认为这应该是 Spring 中已经存在的传递依赖项,我不应该手动添加它...

解决方案

谢谢 Smajl,添加

<依赖><groupId>nz.net.ultraq.thymeleaf</groupId><artifactId>thymeleaf-layout-dialect</artifactId></依赖>

也为我解决了这个问题.

I have a simple Spring Boot application in version 1.5.7 and I am trying to migrate it to version 2.0.0. I am almost done but there is one last piece missing and that is Thymeleaf.

Everything was working fine in the old version but after the migration, Spring Boot stopped resolving any templates (both pages and emails).

I have all templates src/main/resources/templates. Additionaly, I have layout called default in src/main/resources/templates/layout which looks like this:

<!DOCTYPE html>
<html>
<head th:replace="fragments/header :: head"></head>
<body>

    <div id="page">
        <nav class="navigation" th:replace="fragments/navigation"></nav>

        <div class="container">
            <div layout:fragment="container"></div>
        </div>
    </div>
</body>
</html>

My pages link to this layout like this:

<!DOCTYPE html>
<html lang="en"
  xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  layout:decorate="layout/default">

<body>

    <div layout:fragment="container">
...
</body>
</html>

The navigation fragment in localted in src/main/resources/templeats/fragments

In Spring Boot 2, the login page is rendered but the layout is not applied (so the navigation bar and styles are missing). Did something change in version 2.0.0? I have not found any solution to this in officials docs or migration guide.

EDIT: As suggested in the answer, it is caused by migrating to Thymeleaf 3. I updated my question with some changes reflecting the migration guide but the code is still not injecting the layout.

I have tried layout:data-layout-decorate=~{layout/default} and layout:data-layout-decorate=~{layout/default.html} as well

I made it work with manually adding the thymeleaf dialect dependency:

compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')

But I thought that this should be a transitive dependency already present in Spring and I should not have to add it manually...

解决方案

Thank you Smajl, adding

<dependency>
    <groupId> nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

solved the issue also for me.

这篇关于迁移到 Thymeleaf 3 后,Thymeleaf 停止解析布局模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
Java开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆