Springboot 使用swagger一直重定向

 1.现象

  就是一访问就弹出一个框框一直重定向到你崩溃,必须要把页面关掉才行。。。

2.可能的问题

(1)你的启动类里面没有添加    @EnableSwagger2Doc  注解;

(2)你的yml里面没有打开开关: 

 swagger: 

   enabled: true

(3)你用了拦截器(比如:登录验证的拦截器)(比如:某个继承了WebMvcConfigurationSupport的东西),没有把它的资源路径exclude掉:

  【划重点】:也很有可能你把exclude的路径写错了。比如部署了war包,经常会比localhost访问多一个项目名称。一定要检查啊!!!

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/assets/**").addResourceLocations("/resources/assets/");
        //swagger增加url映射
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
       
    }
//这里配置拦截器的拦截路径和不拦截路径
 @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.logInterceptor).addPathPatterns("/**");
        registry.addInterceptor(this.authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", "/webjars/**", "/**/swagger-resources/**");
    }

(4)还是不行,试试这个:

@EnableSwagger2Doc
@SpringBootApplication
public class ServerApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ServerApplication.class);
    }
}

(5)没办法了。请教大佬让大佬帮你看源码怎么配置吧。(狗头)

猜你喜欢

转载自www.cnblogs.com/haiyoushenmemingzi/p/11300635.html