在将Spring从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迁移指南 +阅读弹簧-启动释放,但没有成功.
模板片段(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 fragment )
<!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);
}
}发布于 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用户的附加配置步骤。
下面从上面的链接安装步骤应该是有帮助的,即:
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.4.1</version>
</dependency>@Bean:@Bean
public LayoutDialect layoutDialect() {
return new LayoutDialect();
}https://stackoverflow.com/questions/59739258
复制相似问题