美文网首页Spring-Boot
springboot设置静态资源不拦截的方法

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

作者: Dream城堡 | 来源:发表于2018-08-28 19:12 被阅读21次

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设置静态资源不拦截的方法

    本文链接:https://www.haomeiwen.com/subject/pmgqwftx.html