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

进入该类,我们会发现没有@EnableConfigurationProperties注解,接下来进行猜想
1.可能是存在内部类中;
2.有可能不是这个类 ;

我们经过前面的猜想,终于找到了有关静态资源路径的方法
二、webjars方式
webjars官网:https://www.webjars.org/

我们导入jquery测试
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
分析源码可知
如果访问到/wenjars/**META-INF/resources/webjars/
 
三、导入静态资源


1.导入一个静态资源
在resouces下的static建立一个index.
2.js在浏览器中输入http:localhost:8080/index.js
静态资源文件夹访问的顺序:
1. resouces
2. static
3. public
四、自定义静态资源路径(不推荐)
spring.resources.static-locations=/**
到此这篇关于SpringBoot之导入静态资源详解的文章就介绍到这了,更多相关SpringBoot导入资源内容请搜索社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持社区! |