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

Posted 城南少年与猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot设置静态资源不拦截的方法相关的知识,希望对你有一定的参考价值。

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

springboot不拦截静态资源需配置如下的类:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
    /**
     * 配置静态访问资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}

以上是关于springboot设置静态资源不拦截的方法的主要内容,如果未能解决你的问题,请参考以下文章