当前位置:   article > 正文

【Spring Boot】addResourceHandlers(ResourceHandlerRegistry registry)中文无法访问_addresourcehandlers 中文

addresourcehandlers 中文

一 问题复现

使用springboot配置映射静态资源目录后,英文和数字可以正常进行访问,但是中文就提示404

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/file/video/**").addResourceLocations(props.getVideoFolder());
	}
  • 1
  • 2
  • 3
  • 4

二 解决办法

原文传送门,有分析过程

一 UrlPathHelper 设置不decodeurl

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper=new UrlPathHelper();
        urlPathHelper.setUrlDecode(false);
        urlPathHelper.setDefaultEncoding(StandardCharsets.UTF_8.name());
        configurer.setUrlPathHelper(urlPathHelper);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {  registry.addResourceHandler("/files/**").addResourceLocations("file:E:/FileUpload/HmiInterface/");
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

二 使用原来的AntPathMatcher (推荐)

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  • 1
  • 2
  • 3
  • 4

版本问题,最为致命

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/917463
推荐阅读
相关标签
  

闽ICP备14008679号