【Swagger笔记】Unable to infer base url

在进入Swagger接口测试界面时,弹出一个弹窗,内容:Unable to infer base url. ……

大体的意思为:Swagger获取不到它需要的资源,原因可以从两方面考虑:

  • Swagger相关的配置没配置好。这种情况相关配置教程很多,请用自己喜欢的引擎搜索

  • Swagger没有获得访问路径的权限。例如之前刚配置好的权限管理,如Shiro、Security等,需要对Swagger请求访问的相关路径进行开放。相关路径如下:

    • /swagger-ui.html
    • /webjars/**
    • /v2/**
    • /swagger-resources/**

eg:在Shiro中配置开发相关路径:

@SpringBootConfiguration
public class MyWebConfiguration implements WebMvcConfigurer{
    
    
    //······
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
    
    
        registry.addInterceptor(getLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v2/**")
                .excludePathPatterns("/swagger-resources/**");
    }
    //······
}

猜你喜欢

转载自blog.csdn.net/weixin_40849588/article/details/107635814