以下内容转载自
https://www.cnblogs.com/gu-bin/p/11129066.html
总结:
1、自动配置
xxxxAutoConfiguration:帮我们给容器中自动配置组件;
xxxxProperties:配置类来封装配置文件的内容;
2、WebMvcAutoConfiguration类自动为我们注册了如下目录为静态资源目录,也就是说直接可访问到资源的目录。优先级从上到下。
所以,如果static里面有个index.html,public下面也有个index.html,则优先会加载static下面的index.html,因为优先级!
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
/:当前项目的根路径
3、默认首页(PS:就是直接输入ip:port/项目名称默认进入的页面)WebMvcAutoConfiguration类自动为我们注册了如下文件为默认首页。
classpath:/META-INF/resources/index.html
classpath:/resources/index.html
classpath:/static/index.html
classpath:/public/index.html
/index.html
优先级从上到下。
所以,如果static里面有个index.html,public下面也有个index.html,则优先会加载static下面的index.html,因为优先级!
4、favicon.ico这个图标。只要把favicon.ico放到如下目录下,就会自动生效。
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
/:当前项目的根路径
5、webjars
所有/webjars/**都从classpath:/META-INF/resources/webjars/
路径下去找对应的静态资源。什么是webjars?
就是以jar包的方式引入静态资源。
官网地址:http://www.webjars.org/。类似于maven仓库。
我们可以做个例子,将jquery引入到项目中
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
看项目依赖
image.png
会自动为我们引入jquery,要怎么使用呢?我们上面说过:
所有/webjars/*都从classpath:/META-INF/resources/webjars/
路径下去找对应的静态资源。
所以我们启动项目,访问:http://localhost:8080/webjars/jquery/3.3.1/jquery.js
即可。