SpringBoot设置静态资源访问目录

公司项目使用SpringBoot作为后端,Vue开发前端页面。在前台上传完图片后,需要查看。路径被拦截,查看SpringBoot知道是没有设置访问路径。

看到几篇文章有介绍,关于官网的介绍,Mark一下。同时记录一下项目中设置静态资源路径的方法。

文章传送门一:http://blog.csdn.net/isea533/article/details/50412212

文章传送门二:https://www.cnblogs.com/java-synchronized/p/7091723.html

官网文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html

SpringBoot静态资源处理

默认情况下Spring Boot 使用WebMvcAutoConfiguration中配置的各种属性。

默认映射的文件夹有:

  • classpath:/META-INF/resources

  • classpath:/resources

  • classpath:/static

  • classpath:/public

上面这几个都是静态资源的映射路径,优先级顺序为:META-INF/resources > resources > static > public

修改默认访问路径

可以通过修改spring.mvc.static-path-pattern来修改默认的映射**,配置如下:

application.properties

spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path},file:${web.vue-path}

变量的配置如下:

web.upload-path=C:/Hpsy/
# 项目上传文件路径
# web.upload-url=http://47.93.246.239:8100/api/
web.vue-path=C:/javaProject/hpsy/admin/

程序的jar包放在了

C:/javaProject/hpsy/

这个路径下,所以,web.vue-path写成该路径下的admin文件夹。

我们项目使用的JWT进行校验,admin路径需要放开:

#JWT json web token 分布式token的配置
jwt.info.clientId=098f6bcd4621d373cade4e832627b4f6
jwt.info.base64Secret=MDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjY=
jwt.info.name=restapiuser
jwt.info.expiresSecond=1728000
#480小时

jwt.exclude.urlPatterns[0]=/admin

关于如何集成JWT,后续会记录一下。

访问方式:

//index.html 是admin路径下的HTML文件
http://47.93.246.239:8100/api/admin/index.html#/login
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值