WebMvcAutoConfiguration.java中的关键源码
所有/webjars/** 都去 classpath:/META-INF/resources/webjars/ 找资源
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21@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(); if (!registry.hasMappingForPattern("/webjars/**")) { customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/") .setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl)); } String staticPathPattern = this.mvcProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern) .addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations())) .setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl)); } }
/**访问当前项目的任何资源,
/**访问当前项目的任何资源(静态资源的文件夹)
复制代码
1
2
3
4
5
6
7classpath:/META-INF/resources/ classpath:/resources/ classpath:/static/ classpath:/public/ <!--当前项目的根路径--> /
测试访问js资源
欢迎页面映射
静态资源文件夹下的所有index.html页面,被 /** 映射:
在public下添加index.html页面,测试:
webjars 以jar包 maven依赖方式引入外部资源
https://www.webjars.org/
引入webjar资源后的对应目录结构:
启动SpringBoot访问资源:
更改SpringBoot页面的icon:
复制代码
1
2
3
4在2.x以前的版本。直接将你需要的favicon.ico文件倒挡static下面就可以。 2.X以后的版本,取消了自动配置,需要人手动去在每一个页面添加???
为啥写favicon.ico都不行的,非要改名加个1啥的才可以?
谷歌清空缓存测试 favicon.ico
火狐更换端口到全新的8899测试favicon.ico
最后
以上就是合适嚓茶最近收集整理的关于SpringBoot学习-part19 webjars和静态资源配置的全部内容,更多相关SpringBoot学习-part19内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复