java - Spring Boot Freemarker 从 2.2.0 升级失败

标签 java spring spring-boot kotlin freemarker

将 spring-boot-parent 升级到 2.2.0.RELEASE 后,我基于 freemarker 的 Spring Boot Web 应用程序无法正确处理请求。

我有一个 @Controller 服务于 /hellosrc/main/resources/templates/hello.ftl

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

根据请求,它只是出现在一个错误页面上,上面写着出现意外错误(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.RELEASE 之前一直运行良好
这里有什么问题?

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

最佳答案

这是由于 Spring Boot 2.2.0 中具有默认 freemarker 后缀的重大更改。
Freemarker 文件现在应该以 .ftlh 而不是 .ftl 结尾。
.ftlh 启用 HTML 自动转义功能。

可以找到更改此内容的提交 here .它旨在修复 this issue freemarker 默认设置应该更安全,它启用自动 HTML 转义。

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

关于java - Spring Boot Freemarker 从 2.2.0 升级失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58540560/

相关文章:

spring - 为什么spring security oauth2客户端需要AuthorizationRequestRepository?

java - JSP 将 var 传递给 css 样式

java - 加载时出现 Eclipse jvm.dll 错误

spring - ReflectionTestUtils 在 Spring 测试中不能与 @Autowired 一起使用

java - UTF-8 URL 解码/编码

java - if...else Spring Boot 模拟测试中的语句问题

java - 如何为 Spring Boot 应用程序配置端口

Springboot无法读取Yaml配置

java - java中的静态方法main

java - 这段代码中哪个线程正在 hibernate ?主线程还是 t1 线程?