springboot设置静态资源不拦截的方法

1. 代码层面,springboot不拦截静态资源需配置:

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class WebMvcConfig implements WebMvcConfigurer{
	
	/**
	 * 目前是解决的是swagger和微信授权文件无法被搜索到的问题
	 * @author Nanci
	 */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 解决 swagger-ui.html 404报错
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        // 解决 doc.html 404 报错
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/swagger/**").addResourceLocations("classpath:/static/swagger/");
        registry.addResourceHandler("/v2/api-docs/**").addResourceLocations("classpath:/static/swagger/");
        registry.addResourceHandler("/pages/**").addResourceLocations("classpath:/static/pages/");
        // 解决静态资源文件无法被搜索的问题
        registry.addResourceHandler("/9526435554.txt").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/MP_verify_WoMVU5VvlzzQeYhV.txt").addResourceLocations("classpath:/static/");
    }
    
}

2. 代码解决不了,请检查你的网关系统,看看里面是怎么配置的。。。。不要以为都是代码的问题钻牛角尖(因为我钻了)


版权声明:本文为zheng2780071070原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。