Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened

1.问题描述

在WebMvcConfig中配置模板解析器后,反而无法加载模板,报找不到模板的错误。诡异的地方是,删掉自定义配置,使用系统自带的配置就完全没问题。

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class“)”

Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened because it does not exist

Caused by: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/500]")

Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened_第1张图片

2.原因分析

WebMvcConfig.java文件中覆盖suffix类,但是又没有在.properties中设置相关属性。

Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened_第2张图片

如果没有重写SpringResourceTemplateResolver类,会使用默认配置。但是如果重写的话,系统会到当前对象中去找到相关配置。

Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened_第3张图片

3.解决办法

1)在.properties文件中设置相关属性

spring.thymeleaf.suffix=.html

2)在模板解析函数中使用setSuffix()函数进行设置

Caused by: java.io.FileNotFoundException: class path resource [templates/500] cannot be opened_第4张图片

你可能感兴趣的:(debug/错误日志)