springboot静态资源映射
springboot静态资源映射
WebMvcAutoConfiguration
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!this.resourceProperties.isAddMappings()) {
logger.debug("Default resource handling disabled");
return;
}
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
CacheControl cacheControl = this.resourceProperties.getCache()
.getCachecontrol().toHttpCacheControl();
// 读取webjars下的静态文件
// classpath:/META-INF/resources/webjars/
if (!registry.hasMappingForPattern("/webjars/**")) {
customizeResourceHandlerRegistration(registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.setCachePeriod(getSeconds(cachePeriod))
.setCacheControl(cacheControl));
}
// 静态资源文件夹映射
// {"classpath:/META-INF/resources/", "classpath:/resources/","classpath:/static/", "classpath:/public/" }
String staticPathPattern = this.mvcProperties.getStaticPathPattern();
if (!registry.hasMappingForPattern(staticPathPattern)) {
customizeResourceHandlerRegistration(
registry.addResourceHandler(staticPathPattern)
.addResourceLocations(getResourceLocations(
this.resourceProperties.getStaticLocations()))
.setCachePeriod(getSeconds(cachePeriod))
.setCacheControl(cacheControl));
}
}
// 欢迎页 /**
@Bean
public WelcomePageHandlerMapping welcomePageHandlerMapping(
ApplicationContext applicationContext) {
return new WelcomePageHandlerMapping(
new TemplateAvailabilityProviders(applicationContext),
applicationContext, getWelcomePage(),
this.mvcProperties.getStaticPathPattern());
}
静态资源路径可以自定义:
spring.resources.static-locations=classpath:/xxx/,classpath:/yyy/,classpath:/zzz/
springboot静态资源映射的更多相关文章
- springboot静态资源映射规则
一.所有/webjars/**的请求,都会去classpath:/META-INF/resources/webjars/下的目录去找资源. 二.访问/**,即访问任何资源,如果没有controller ...
- Springboot静态资源映射 “/” 引发的血案
因为少写一个 / 浪费已个下午的时间,
- spring-boot配置静态资源映射的坑:properties文件不能添加注释
如此博文所述,Spring Boot 对静态资源映射提供了默认配置 默认将 /** 所有访问映射到以下目录:classpath:/staticclasspath:/publicclasspath:/r ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- Springboot学习02-webjars和静态资源映射规则
Springboot学习01-webjars和静态资源映射规则 前言 1-以前我们在IDEA中创建一个项目,添加web依赖包,我们现在是一个web应用,应该在man目录下面有一个webapp文件夹,将 ...
- SpringBoot——Web开发(静态资源映射)
静态资源映射 SpringBoot对于SpringMVC的自动化配置都在WebMVCAutoConfiguration类中. 其中一个静态内部类WebMvcAutoConfigurationAdapt ...
- SpringBoot:静态资源映射、定制404、配置icon
目录 静态资源映射规则 定制首页 定制错误页面 配置 icon 静态资源映射规则.定制首页.定制404页面.配置网站的图标 静态资源映射规则 SpringBoot中对于静态资源(css,js,img. ...
- java框架之SpringBoot(4)-资源映射&thymeleaf
资源映射 静态资源映射 查看 SpringMVC 的自动配置类,里面有一个配置静态资源映射的方法: @Override public void addResourceHandlers(Resource ...
- springboot静态资源处理
转:https://blog.csdn.net/catoop/article/details/50501706 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConf ...
随机推荐
- ymal
https://blog.csdn.net/beginya/article/details/76768968 https://www.jianshu.com/p/97222440cd08
- day06_03 购物车讲解01
1.0 思路 1.1 列表嵌套 # name1 = ['mac','book','bike','kindle'] a = [[1,2,3],'alex',(2,3,4)] print(a[0]) #& ...
- Leetcode 665.非递减数列
非递减数列 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i ...
- vue实现数据的增删改查
在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...
- Oracle 数据库导出时 EXP-00008;ORA-00904
问题是客户端和服务器端版本问题,我本地是11g,而服务器端是10g. 规则1:低版本的exp/imp可以连接到高版本(或同版本)的数据库服务器,但高版本的exp/imp不能连接到低版本的数据库服务器. ...
- jQuery选择器之全选择器(*选择器)
在css中,经常会在第一行写下这样一段样式: * { margin:; padding:; } 通配符*意味着给所有的元素设置默认的边距.jQuery中我们也可以通过传递*选择器来选中文档页面中的元素 ...
- H3C交换机端口链路聚合
H3C交换机端口链路聚合 以太网链路聚合 -- 以太网链路聚合配置命令 -- lacp system-prioritylacp system-priority命令用来配置系统的LACP优先级.undo ...
- 《c程序设计语言》读书笔记-5.4-指针实现strend
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...
- poj 1390 区间dp
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5035 Accepted: 2065 Descriptio ...
- CSU 2136 ——湖南多校对抗赛 I
2136: 统帅三军! Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 55 ...