解决SpringBoot静态资源不渲染问题
Posted 康小庄
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决SpringBoot静态资源不渲染问题相关的知识,希望对你有一定的参考价值。
今天做项目时SpringBoot渲染不了static
下的静态文件,通过查资料发现,是maven加载,编译时漏掉了,必须手动在pom.xml
手动添加
浏览器打印报错如下
添加pom.xml
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.html</include>
<include>**/*.js</include>
<include>**/*.css</include>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.html</include>
<include>**/*.js</include>
<include>**/*.css</include>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
要是想要一口气包括所有可以直接**/*.*
,简单粗暴
<include>**/*.*</include>
添加后重新刷新pom.xml
文件即可,问题解决
以上是关于解决SpringBoot静态资源不渲染问题的主要内容,如果未能解决你的问题,请参考以下文章
Spring boot:thymeleaf 没有正确渲染片段