Spring boot通过配置(spring.resources.static-location) 加载静态资源的路径

上次通过创建类,进行Springboot中的静态资源配置,来实现文件上传,下载,显示等功能。

https://blog.csdn.net/weixin_41986096/article/details/105397368

实际上还有一种就是通过配置来实现的

我们在applicat.yml文件中添加如下配置:

spring:
  resources:
    static-locations: file:${oss.local.upload-file-path}
 
#文件上传配置
#使用的上传存储空间,local本地,aliyun:阿里云
oss:
 client-type: local
 #默认上传目录
 base_dir:
 #允许的文件扩展名
 allowed_extension: mp4,bmp, gif, jpg, jpeg, png,doc, docx, xls, xlsx, ppt, pptx,html,htm,txt,rar, zip, gz, bz2,pdf
 #最大文件大小 50M
 max_size: 52428800
 local:
   domain: 本地地址
   upload-file-path: F:/img
 aliyun:
   #阿里云api的内或外网域名
   endpoint: oss-cn-beijing.aliyuncs.com
   #阿里云api的密钥access key id
   access-key-id: 阿里云ID
   #阿里云api的密钥access key secret
   access-key-secret: 阿里云 key
   #阿里云api的bucket名称
   bucket-name: jeewebbbs
   #外部访问域名
   domain:  阿里云地址

通过设置spring.resources.static-locations自定义Spring boot加载前端静态资源路径

现在同样的方式,不用去创建类,在F盘符下img下放一张图片,作为静态资源

我们访问:

 

posted @ 2020-04-19 15:09  路大师_XA  阅读(23595)  评论(0编辑  收藏  举报