博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swagger配置完之后无法访问
阅读量:7039 次
发布时间:2019-06-28

本文共 2568 字,大约阅读时间需要 8 分钟。

在使用swagger配置后,一开始可以正常访问,在后来打开链接的时候一直出现下面的弹框

 

Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually

折磨了一个小时,网上找了各种办法,包括一些在springboot启动类加上组件扫描等等,都不行

后来尝试换了一下swagger的版本,之前是2.7.0,换成2.9.2现在可以正常访问,但是原因我还不清楚,希望看到的大神可以给与帮助。

下面是我的配置:

/** * Swagger2API文档的配置 */@Configuration@EnableSwagger2public class Swagger2Config {    @Bean    public Docket createRestApi(){        return new Docket(DocumentationType.SWAGGER_2)                .apiInfo(apiInfo())                .select()                .apis(RequestHandlerSelectors.basePackage("com.elazine.mall.admin.controller"))                .paths(PathSelectors.any())                .build()                .securitySchemes(securitySchemes())                .securityContexts(securityContexts());    }    private ApiInfo apiInfo() {        return new ApiInfoBuilder()                .title("mall后台系统")                .description("mall后台模块")                .contact("macro")                .version("1.0")                .build();    }    private List
securitySchemes() { //设置请求头信息 List
result = new ArrayList<>(); ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header"); result.add(apiKey); return result; } private List
securityContexts() { //设置需要登录认证的路径 List
result = new ArrayList<>(); result.add(getContextByPath("/brand/.*")); result.add(getContextByPath("/product/.*")); result.add(getContextByPath("/productCategory/.*")); return result; } private SecurityContext getContextByPath(String pathRegex){ return SecurityContext.builder() .securityReferences(defaultAuth()) .forPaths(PathSelectors.regex(pathRegex)) .build(); } private List
defaultAuth() { List
result = new ArrayList<>(); AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; result.add(new SecurityReference("Authorization", authorizationScopes)); return result; }}

  

转载于:https://www.cnblogs.com/huyh468/p/11049652.html

你可能感兴趣的文章
C/C++实现正负数四舍五入
查看>>
android获取系统应用大小的方法
查看>>
swift菜鸟入门视频教程-05-控制流
查看>>
解决火狐中用JQUERY .removeAttr()无法去除元素属性的方法
查看>>
100723H Obfuscation
查看>>
matplotlib numpy scipy 的安装
查看>>
redux在react中的使用
查看>>
洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
查看>>
Angular进阶教程二
查看>>
prism wp7 applicationbar 不能立即触发textbox 的双向绑定
查看>>
repo sync error: .repo/manifests/: contains uncommitted changes
查看>>
cmd 操作命令
查看>>
java.lang.NoSuchMethodError
查看>>
糗事⊙︿⊙
查看>>
AES加密解密 助手类 CBC加密模式
查看>>
网络ip
查看>>
JAVA连接SAP
查看>>
FZU2169 shadow题解
查看>>
教你正确打开async/await关键字的使用
查看>>
python 字符串复制
查看>>