博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot | 如何配置静态资源的地址与访问路径
阅读量:4183 次
发布时间:2019-05-26

本文共 971 字,大约阅读时间需要 3 分钟。

一、spring.mvc.static-path-pattern

#这表示只有静态资源的访问路径为/static/**时,才会处理请求 e.g:localhost:9001/static/1.txt#spring.mvc.static-path-pattern=/static/**

二、spring.resources.static-locations

 

#这表示按照下面路径的顺序依次查找,才会处理请求 e.g:localhost:9001/1.txt#spring.resources.static-locations=classpath:/static,classpath:/upload

项目结构:

 

访问出现如下结果表明访问成功。

 

 

三、静态资源的Bean配置

 

/** * @author xiaobu * @version JDK1.8.0_171 * @date on  2019/1/14 12:46 * @description V1.0 */@Configurationpublic class WebMvcConfig implements WebMvcConfigurer {   /**     * @author xiaobu     * @date 2019/1/18 13:51     * @param registry  registry     * @descprition  等价于 http://localhost:9001/1.txt 依次在static upload目录下找1.txt文件     * @version 1.0     */    @Override    public void addResourceHandlers(ResourceHandlerRegistry registry) {        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/","classpath:/upload/");    }	}

 

 


 易混淆的点:

项目路径:

#默认是server.servlet.context-path=/

#server.servlet.context-path=/test

转载地址:http://dfgai.baihongyu.com/

你可能感兴趣的文章
[LeetCode] Validate Binary Search Tree 验证二叉搜索树
查看>>
[LeetCode] Recover Binary Search Tree 复原二叉搜索树
查看>>
[LeetCode] Same Tree 判断两颗树是否相等
查看>>
HTTP协议
查看>>
HTTPWeb服务器---HTTP整体设计框架
查看>>
[剑指offer] 替换空格
查看>>
[剑指offer] 翻转字符串
查看>>
敏捷开发扫盲篇
查看>>
八大排序算法之插入排序
查看>>
八大排序算法之选择排序
查看>>
八大排序算法之交换排序
查看>>
UDP协议
查看>>
游戏服务器:到底使用UDP还是TCP
查看>>
IP协议
查看>>
连续子数组的最大和
查看>>
毕业设计--相关优秀博客论坛与文章
查看>>
go 语言源码编译
查看>>
golang 单元测试包命令
查看>>
FFMPEG 安装 教程(支持mp3)
查看>>
windows ubuntu 双系统
查看>>