Spring Boot Freemarker从2.2.0升级失败 [英] Spring Boot Freemarker fails from 2.2.0 upgrade

查看:117
本文介绍了Spring Boot Freemarker从2.2.0升级失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Spring-Boot-Parent升级到2.2.0.RELEASE时,我的基于Freemarker的Spring Boot Web应用程序无法正确处理请求。

我有一个@Controller/hello提供服务的src/main/resources/templates/hello.ftl

@Controller
class HelloController() {
    @RequestMapping(value = ["/hello"])
    fun hello(): String {
        return "hello"
    }
}

根据请求,它只会出现错误页面,上面写着There was an unexpected error (type=Not Found, status=404).

错误堆栈跟踪不能说明什么。它只写着org.springframework.web.servlet.resource.ResourceHttpRequestHandler: Resource not found

我的pom.xml基本情况如下:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.0.RELEASE</version>
    <relativePath/>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
</dependencies>

在升级到Spring Boot 2.2.0版本之前,它一直运行得很好
这里有什么问题?

  • 根据rules,这是一个自我回答的问题,以防止其他可怜的人像我一样受苦。

推荐答案

这是由于Spring Boot 2.2.0中使用默认免费标记后缀的突破性更改。
Freemarker文件现在应该以.ftlh而不是.ftl结尾。
.ftlh启用HTML自动转义功能。

here可以找到更改了这一点的提交。它的目的是修复this issueFreemarker的默认设置应该更安全,这就是启用自动的HTML转义。

您应该在升级前阅读的2.2.0.RELEASE的完整更改日志here

这篇关于Spring Boot Freemarker从2.2.0升级失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆