问题描述
我使用带有 swagger 3 的 Springboot:
<!-- SWAGGER -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
我对所有端点使用默认的 /api
前缀。
这是我配置 SwaggerConfig 的方式:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static final String AUTHORIZATION_HEADER = "Authorization";
@Bean
public Docket api() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.securityContexts(Collections.singletonList(securityContext()))
.securitySchemes(Collections.singletonList(apiKey()))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build().pathMapping("/api");
return docket;
}
private ApiKey apiKey() {
return new ApiKey("JWT",AUTHORIZATION_HEADER,"header");
}
// ......
}
当我尝试访问我的 swagger-ui http://myhost/swagger-ui
时,我收到一个带有此消息的弹出窗口 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:
,要求我定义位置。
当我手动输入前缀时:http://myhost/api
那么一切都很好。
知道如何定义我的 REST API 前缀吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)