小编Rob*_*son的帖子

如何将布局方言添加到spring-boot thymeleaf自动配置文件中

美好的一天,我刚刚创建了一个使用Spring-boot和thymeleaf的项目.我试图利用布局方言来利用它的"像模板一样的瓷砖".我已经查找了这个问题,每个响应都建议我添加布局方言作为spring-boot配置文件.但是我在这方面的每一次尝试都失败了,最近的一次尝试来自这个链接我如何在弹簧靴中添加百里香的方言?.所以我在配置文件中添加了这个

@Configuration
public class ThymleafConfiguration {
    @Bean
    public LayoutDialect layoutDialect() {
        return new LayoutDialect();
    }
}
Run Code Online (Sandbox Code Playgroud)

但它始终导致:

"Error resolving template "layout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (welcomeHome:4)"
Run Code Online (Sandbox Code Playgroud)

但是layout.html位于/ resources/templates文件夹中,所以我知道它不是位置不匹配.我的目标只是添加Dialect布局而不会破坏太多的spring-boot自动配置设置.我的pom既有百里香 - 布局 - 方言,也有百里香的启动依赖.

welcomeHome.html

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="layout.html">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "layout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (welcomeHome:4)
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245) …
Run Code Online (Sandbox Code Playgroud)

maven thymeleaf spring-boot

7
推荐指数
1
解决办法
9279
查看次数

标签 统计

maven ×1

spring-boot ×1

thymeleaf ×1