Spring Boot 默认的静态资源位置

Spring Boot 默认的静态资源位置在 resource 目录下的 static 文件夹中。

spring boot 指定 static springboot static location_spring

一个示例:

在static 文件夹中新建文件:hello.js写入:

hello Spring Boot !

spring boot 指定 static springboot static location_自定义_02

运行项目,打开浏览器,输入:

localhost:8080/hello.js

如下图:

spring boot 指定 static springboot static location_spring_03

自定义静态资源位置

1、首先在 resources 目录下新建文件夹you,再在you目录下新建文件hello.js

输入:

hello you !

spring boot 指定 static springboot static location_静态资源_04

2、在application.properties 文件中配置如下:

spring.resources.static-locations=classpath:/you/

spring boot 指定 static springboot static location_静态资源_05

再次运行项目,打开浏览器,按 Ctrl+F5 强制刷新,如下图:

spring boot 指定 static springboot static location_spring_06