gpt4 book ai didi

java - Springfox 从 2.9.2 更新到 2.10.4 后错误 "Unable to infer base url. ..."

转载 作者:行者123 更新时间:2023-12-01 13:20:08 25 4
gpt4 key购买 nike

我刚刚将 Spring Boot 应用程序(版本 2.3.1.RELEASE)中的 Springfox 依赖项从 2.9.2 更新到 2.10.4。

<spring-boot.version>2.3.1.RELEASE</spring-boot.version>
<swagger.version>2.10.4</swagger.version>
因类(class)变动 springfox.documentation.*包,我不得不将我的配置类中的注释从
@EnableSwagger2
@EnableSwagger2WebMvc
此外,谓词导入从 Google Guave 更改为 java.util.function .我当前的配置类看起来像这样
package de.rewe.zlip.config;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).globalOperationParameters(globalOperationParameters())
.select()
.apis(sourceScannedForRestApis())
.paths(PathSelectors.any())
.build()
.apiInfo(apiEndPointsInfo())
.genericModelSubstitutes(Optional.class);
}

private List<Parameter> globalOperationParameters() {
List<Parameter> operationParameters = new LinkedList<>();
Parameter authorizationParameter = new ParameterBuilder().name("Authorization")
.description("Your Bearer token ")
.modelRef(new ModelRef("string"))
.parameterType("header")
.build();
operationParameters.add(authorizationParameter);
return operationParameters;
}

private Predicate<RequestHandler> sourceScannedForRestApis() {
return RequestHandlerSelectors.basePackage("de.my.package");
}

private ApiInfo apiEndPointsInfo() {
return new ApiInfoBuilder().title("TEST SERVER REST API")
.description("REST API provided for the TEST web application")
.contact(contactInfo())
.version("v1.0")
.build();
}

private Contact contactInfo() {
return new Contact("Test Team", "https://", "test@test.com");
}

}
当我现在打开 http://localhost:8080/swagger-ui.html 时,我收到以下消息:

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


不用说,相同的配置(除了上面提到的 2 个更改)适用于 2.9.2。前面问题中的大部分提示都是添加
@EnableSwagger2
但由于此注释在 2.10.X 中已更改为 @EnableSwagger2Mvc@EnableSwagger2Flux这无济于事。

最佳答案

来自 springfox issue tracker :

Oh please dont use 2.10... it was an intermediate step so that people who were on 3.0.0-SNAPSHOT can continue using a released version if needed.


我建议暂时恢复到 2.9.2。

关于java - Springfox 从 2.9.2 更新到 2.10.4 后错误 "Unable to infer base url. ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62573076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com