Springboot:静态资源加载(七)

WebMvc自动配置:

搜索WebMvcAutoConfiguration自动装配类:

第一种方式通过webjars加载静态资源:

https://www.webjars.org(通过maven加载依赖环境的方式)

比如:要载入jquery的环境:

 <dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.4.1</version>
</dependency>

查看jquery的静态资源目录:

访问静态资源:http://localhost/webjars/jquery/3.4.1/jquery.js

第二种方式通过配置目录访问静态资源:

"classpath:/resources/", #优先级高
"classpath:/static/",    #优先级中
"classpath:/public/"     #优先级低

当然也可以自定义静态资源目录,但默认配置就会失效

spring:
  mvc:
    static-path-pattern: /applesnt
posted @ 2020-04-10 23:30  努力的校长  阅读(450)  评论(0编辑  收藏  举报