1、静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户通过浏览器直接读取。

2、在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

3、在Springboot中可以直接在配置文件中覆盖默认的静态资源路径的配置信息:

#自定义的属性,指定了一个路径,注意要以/结尾
web.upload-path=D:/temp/study13/

#表示所有的访问都经过静态资源路径
spring.mvc.static-path-pattern=/** #覆盖默认配置,所以需要将默认的也加上否则static、public等这些路径将不能被当作静态资源路径
#在最末尾的file:${web.upload-path}中的file:表示是一个具体的硬盘路径,其他的使用classpath指的是系统环境变量
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path}

4、在SpringBoot开发中,可以在Java代码中覆盖默认静态资源配置

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter { @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { if(!registry.hasMappingForPattern("/static/**")){
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
super.addResourceHandlers(registry);
} }

5、由于Spring Boot 默认资源路径配置的问题,使用IDEA开发Spring Boot应用时,会导致一个问题————浏览器、编辑器 不能同时访问 JS 等资源的问题。这时往往通过配置 4 中的代码,来实现同时访问资源文件的效果

参考知识林:http://www.zslin.com/web/article/detail/23

最新文章

  1. python简单搭建HTTP Web服务器
  2. 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
  3. vs合并压缩css,js插件——Bundler & Minifier
  4. 图结构练习——最短路径(floyd算法(弗洛伊德))
  5. rtp h264注意点(FU-A分包方式说明)
  6. (转)Repeater在无数据记录时显示暂无数据
  7. BZOJ 1416: [NOI2006]神奇的口袋( 高精度 )
  8. WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(二)实现IRequestChannel(2016-03-15 12:35)
  9. Spring+MyBatis+SpringMvc整合Demo
  10. css-子div设置margin-top影响父div
  11. PHP整洁之道
  12. del_cursor 批量删除游标
  13. DDL DML概念 --- Msysql常用命令
  14. (5)Jquery1.8.3快速入门_层次选择器
  15. [20171211]ora-16014 11g.txt
  16. C++ 拷贝构造函数之const关键字
  17. Uva 5002 - The Queue DFS
  18. sublime text 多行代码注释快捷键
  19. asp.net 判断session是否过期
  20. NET Core2基于RabbitMQ对Web前端实现推送功能

热门文章

  1. shell 杀死80端口的所有进程
  2. javaagent使用指南
  3. __gcd-最大公约数
  4. win10回收站右键有2个“CCleaner”怎么删除
  5. F12修改html进行本地js操作页面元素
  6. vue使用formData进行文件上传
  7. 案例:使用BeautifuSoup4的爬虫
  8. how-does-mysql-replication-really-work/ what-causes-replication-lag
  9. Linux MySQL 5.6.43 安装
  10. Linux下 PostgrelSQL 基本操作