addResourceHandler,addResourceLocations springboot-2.6.x不生效

  • 元凶:springboot2.6.*版本后,mvc的路径匹配策略被修改了.
  • 解决方法:降级springboot到2.5.*即可
    在这里插入图片描述
/**
 * @author xiaoChen
 * @description: AUTO GENERATION
 * @date 2022/6/30 10:32
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //    相关技术博客地址:https://blog.csdn.net/qq_19179711/article/details/124930707?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165655995716781683977867%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165655995716781683977867&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-2-124930707-null-null.142^v26^control,157^v15^new_3&utm_term=addresourcehandlers%E4%B8%8D%E7%94%9F%E6%95%88&spm=1018.2226.3001.4187
//    springboot版本:2.6.*,通过该虚拟映射的请求失效、比如:http://localhost:8080/file/1.png ,会报404.
//    原因:从springboot2.6.*版本之后,路径匹配策略改变了.Spring MVC 处理程序映射匹配请求路径的默认策略已从 AntPathMatcher 更改为PathPatternParser。
//    如果需要将默认切换回 AntPathMatcher,可以将 spring.mvc.pathmatch.matching-strategy 设置为 ant-path-matcher
//    springboot版本:2.5.*,可以正常使用
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/file/**").addResourceLocations("file:C://Users//MyAsus//Desktop//springbootdemo//file//");
    }

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值