一、分析源码

我们学完之前的框架,大概知道静态资源过滤是由mvc处理的,然后在分析自动装配的时候会遇到WebMvcAutoConfiguration类,我们点击进入该类,如图所示:

SpringBoot之导入静态资源详解

进入该类,我们会发现没有@EnableConfigurationProperties注解,接下来进行猜想

1.可能是存在内部类中;

2.有可能不是这个类 ;

SpringBoot之导入静态资源详解

我们经过前面的猜想,终于找到了有关静态资源路径的方法

SpringBoot之导入静态资源详解 

二、webjars方式

webjars官网:https://www.webjars.org/

SpringBoot之导入静态资源详解

我们导入jquery测试

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

分析源码可知

如果访问到/wenjars/**META-INF/resources/webjars/

SpringBoot之导入静态资源详解SpringBoot之导入静态资源详解

三、导入静态资源

SpringBoot之导入静态资源详解
SpringBoot之导入静态资源详解

1.导入一个静态资源
在resouces下的static建立一个index.

2.js在浏览器中输入http:localhost:8080/index.js

静态资源文件夹访问的顺序:

1. resouces

2. static

3. public

四、自定义静态资源路径(不推荐)

spring.resources.static-locations=/**
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。