Spring Boot Freemarker从2.2.0升级失败

发布时间:2022-05-31 / 作者:清心寡欲
本文介绍了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基本情况如下:


    org.springframework.boot
    spring-boot-starter-parent
    2.2.0.RELEASE
    


    
        org.springframework.boot
        spring-boot-starter-web
    
    
        org.springframework.boot
        spring-boot-starter-freemarker
    

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

推荐答案

这是由于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升级失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!



[英文标题]Spring Boot Freemarker fails from 2.2.0 upgrade


声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。