springboot项目找不到templates下的静态资源
时间: 2023-07-28 20:59:01 浏览: 86
在Spring Boot项目中,静态资源可以放在src/main/resources/static目录下,模板文件可以放在src/main/resources/templates目录下。如果你的templates下的静态资源找不到,可能是以下几个原因:
1.路径不正确:请确保你的静态资源文件路径正确,例如:如果你的templates文件夹下有个index.html文件,那么访问路径应该是http://localhost:8080/index.html,而不是http://localhost:8080/templates/index.html。
2.配置不正确:Spring Boot默认会将static和templates文件夹下的资源加入到classpath中,如果你更改了默认配置,需要在application.properties或application.yml中进行配置,例如:
application.properties:
```
spring.resources.static-locations=classpath:/static/
spring.thymeleaf.prefix=classpath:/templates/
```
application.yml:
```
spring:
resources:
static-locations: classpath:/static/
thymeleaf:
prefix: classpath:/templates/
```
3.缓存问题:如果你进行了静态资源的修改,但是在浏览器中没有看到更新,可能是因为浏览器缓存了旧的文件。可以尝试使用Ctrl+F5强制刷新浏览器缓存。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)