本文介紹了Spring Boot Freemarker從2.2.0升級(jí)失敗的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
將Spring-Boot-Parent升級(jí)到2.2.0.RELEASE時(shí),我的基于Freemarker的Spring Boot Web應(yīng)用程序無(wú)法正確處理請(qǐng)求。
我有一個(gè)@Controller為/hello提供服務(wù)的src/main/resources/templates/hello.ftl。
@Controller
class HelloController() {
@RequestMapping(value = ["/hello"])
fun hello(): String {
return "hello"
}
}
根據(jù)請(qǐng)求,它只會(huì)出現(xiàn)錯(cuò)誤頁(yè)面,上面寫著There was an unexpected error (type=Not Found, status=404).。
錯(cuò)誤堆棧跟蹤不能說(shuō)明什么。它只寫著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>
在升級(jí)到Spring Boot 2.2.0版本之前,它一直運(yùn)行得很好。
這里有什么問(wèn)題?
根據(jù)rules,這是一個(gè)自我回答的問(wèn)題,以防止其他可憐的人像我一樣受苦。
推薦答案
這是由于Spring Boot 2.2.0中使用默認(rèn)免費(fèi)標(biāo)記后綴的突破性更改。
Freemarker文件現(xiàn)在應(yīng)該以.ftlh而不是.ftl結(jié)尾。
.ftlh啟用HTML自動(dòng)轉(zhuǎn)義功能。
here可以找到更改了這一點(diǎn)的提交。它的目的是修復(fù)this issueFreemarker的默認(rèn)設(shè)置應(yīng)該更安全,這就是啟用自動(dòng)的HTML轉(zhuǎn)義。
您應(yīng)該在升級(jí)前閱讀的2.2.0.RELEASE的完整更改日志here。
這篇關(guān)于Spring Boot Freemarker從2.2.0升級(jí)失敗的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,






