赞
踩
/** * @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//"); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。