springboot源码分析之静态资源

springboot源码分析之静态资源

导入依赖

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

进入WebMvcAutoConfiguration(自动装配的配置文件)

image-20200820110951020

找到addResourceHandlers
image-20200820112501537

!this.resourceProperties.isAddMappings()是否自定义了配置(如果自定义了配置,则默认的配置失效直接返回)
this.mvcProperties.getStaticPathPattern();得来静态资源路径(private String staticPathPattern = “/**”😉
addResourceLocations()加上()里的资源地址
getResourceLocations(this.resourceProperties.getStaticLocations()获得资源resourceProperties配置;类的StaticLocations地址
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { “classpath:/META-INF/resources/”, “classpath:/resources/”, “classpath:/static/”, “classpath:/public/” };

结论:因此静态资源可以放的位置为:("/**", classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/)-----其中classpath:/META-INF/resources/就是webjars里的资源

image-20200820113211651

优先级:

classpath:/resources/> classpath:/static/>classpath:/public/>"/**",

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值