关于spring boot显示Whitelabel Error Page问题排查指南

目录

由于网上有许多人都遇到了类似的问题,但是每个人的情况又都不一样,所以写出以下指南供各位参考,以便自己排查问题,欢迎各位进行补充

1.写成@Controller/@RestController

参考链接:传送门

2.没有导入thymeleaf的包

<!-- thymeleaf -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

3.模板内有不规范的html标签

导包:

<!-- thymeleaf 不严格解析html -->
<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
</dependency>

并配置:
spring.thymeleaf.mode=LEGACYHTML5

4.包的目录不正确

Application.java为spring boot启动主main
正确包配置如下图(仅供参考):
这里写图片描述

5.addResourceLocations少写了/

例子:

registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");

具体原因可以跟踪

ResourceHttpRequestHandler.getResource

中的

Resource resource = resolveChain.resolveResource(request, path, getLocations());

然后仔细观察路径的变化

猜你喜欢

转载自blog.csdn.net/cenbaolin/article/details/82013055