首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级到Spring 2.2.2. Thymeleaf +thymeleaf 3.0.11.thymeleaf、thymeleaf/布局停止工作

升级到Spring 2.2.2. Thymeleaf +thymeleaf 3.0.11.thymeleaf、thymeleaf/布局停止工作
EN

Stack Overflow用户
提问于 2020-01-14 17:51:42
回答 1查看 1.5K关注 0票数 3

在将Spring从1.5.3.RELEASE迁移到2.2.2.RELEASE之后,Thymeleaf停止了工作。

pom.xml

代码语言:javascript
复制
<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迁移指南 +阅读弹簧-启动释放,但没有成功.

模板片段(Thymeleaf 3.0 layout:decorate)

代码语言:javascript
复制
<!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 fragment )

代码语言:javascript
复制
<!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)

代码语言:javascript
复制
<!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,模型设置如下:

代码语言:javascript
复制
@Configuration
public class MvcConfig implements WebMvcConfigurer {

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

}

默认情况下,上下文路径(/)

代码语言:javascript
复制
@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);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-20 15:10:44

您的问题似乎与Thymeleaf方言有关(参见#4)。Spring 1.5.3.RELEASE支持开箱即用,但2.2.2.RELEASE不支持。

布局方言已经包含在Spring 1.x中的Thymeleaf初学者包中,但是在Spring 2中已经删除了,因此上面提到了Spring 2用户的附加配置步骤。

下面从上面的链接安装步骤应该是有帮助的,即:

  • 添加maven依赖项:
代码语言:javascript
复制
<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>2.4.1</version>
</dependency>
  • 在配置中添加额外的@Bean
代码语言:javascript
复制
@Bean
public LayoutDialect layoutDialect() {
    return new LayoutDialect();
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59739258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档