将 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"
}
}
根据请求,它只是出现在一个错误页面上,上面写着出现意外错误(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/