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

本文解决了一个在自定义WebMvcConfig配置后出现的模板加载失败问题,该问题表现为找不到模板的错误。通过对配置文件的分析,发现是因为自定义配置缺失了必要的suffix设置导致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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]")

2.原因分析

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

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

3.解决办法

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

spring.thymeleaf.suffix=.html

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值