美文网首页
SpringBoot静态资源映射规则

SpringBoot静态资源映射规则

作者: 拉提娜的爸爸 | 来源:发表于2019-08-29 16:45 被阅读0次

1、webjars:springboot中以jar包形式引入的静态资源
所有 /webjars/** ,都去classpath:/META-INF/resources/webjars/找资源;
webjars官网:https://www.webjars.org/
导入静态资源后,资源访问路径为:

如图所示:访问jquery.js的路径为:localhost:8080/webjars/jquery/3.4.1/jquery.js
2、如果是自己的静态资源文件,SpringBoot默认是从以下这些路径中读取的
"classpath:/META‐INF/resources/", 
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"
"/":当前项目的根路径

3、SpringBoot默认首页面为index.html

在SpringBoot默认静态资源访问路径下添加名为index.html文件,那么访问localhost:8080,会自动跳转到这个index.html
4、所有的 **/favicon.ico 都是在静态资源文件下找;
在SpringBoot中,可以把ico格式的图标放在默认静态资源文件路径下,并以favicon.ico命名,应用图标会自动变成指定的图标
自定义的图标
5、SpringBoot也可以在application.properties中手动配置静态资源访问路径,如
# 自定义静态资源访问路径,可以指定多个,之间用逗号隔开
spring.resources.static-locations=classpath:/mystatic/,classpath:/mypublic

注意:自定义静态资源后,SpringBoot默认的静态资源路径将不再起作用

相关文章

网友评论

      本文标题:SpringBoot静态资源映射规则

      本文链接:https://www.haomeiwen.com/subject/lxmiectx.html