springboot 配置静态资源
时间: 2023-04-08 12:05:10 浏览: 105
可以通过在 application.properties 或 application.yml 文件中配置 spring.resources.static-locations 属性来指定静态资源的路径,例如:
application.properties:
spring.resources.static-locations=classpath:/static/
application.yml:
spring:
resources:
static-locations: classpath:/static/
这样就可以将静态资源放在 src/main/resources/static 目录下,并通过访问 /static/xxx.xxx 的方式来访问静态资源。
相关问题
springboot配置静态资源路径
问题:b的Spring Boot配置静态资源路径。
回答:可以在application.properties或者application.yml中使用以下配置改变Spring Boot的静态资源路径:
- application.properties:
```
spring.resources.static-locations=classpath:/static/
```
- application.yml:
```
spring:
resources:
static-locations: classpath:/static/
```
springboot配置静态资源访问多级文件夹
可以通过配置Spring Boot的静态资源路径来访问多级文件夹的静态资源。首先,需要在application.properties或application.yml文件中配置静态资源路径,例如:
```
spring.resources.static-locations=classpath:/static/,classpath:/static/assets/
```
这个配置表示在类路径的static目录下和static/assets目录下查找静态资源。然后,可以通过访问类似于http://localhost:8080/assets/js/main.js的URL来访问静态资源。