spring boot 加入拦截器不能访问swagger或静态资源问题

  1. 实现org.springframework.web.servlet.config.annotation.WebMvcConfigurer 接口,可以保留springboot 的拦截器默认配置,访问资源不用做任何处理。
  2. 继承org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport类,重写相关方法的时候会覆盖掉spring boot默认配置。典型问题:没有做如下配置时,classpath下面的资源文件文件不能直接访问。

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("classpath:/static/");
    }

你可能感兴趣的:(java后台,spring,boot)