尝试使用 spring boot Rest API 配置 swagger 2.10.5,但不断收到错误 Unable to infer base url。这在使用动态 servlet 注册或 API 位于 API 网关后面时很常见
Gradle
compile "io.springfox:springfox-swagger2:2.10.5"
compile "io.springfox:springfox-swagger-ui:2.10.5"
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
配置文件
@Configuration
@ComponentScan
@EnableSwagger2WebMvc
@ComponentScan(basePackageClasses = {
Test.class
})
public class SpringFoxConfig {
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
应用文件
@SpringBootApplication
public class MeroRentalRestApiApplication {
public static void main(String[] args) {
SpringApplication.run(MeroRentalRestApiApplication.class, args);
}
}
SpringFoxConfig和应用在同一个包中
尝试了很多解决方案
https://github.com/springfox/springfox/issues/2191
https://github.com/springfox/springfox/issues/1996
最佳答案
如果有人使用 2.10.5 并面临同样的问题,那么就我而言,我可以通过在下面添加具有相同版本 (2.10.5) 的依赖项 springfox-spring-webmvc 来解决它。我的 pom.xml 文件中已经有 springfox-swagger2 和 springfox-swagger-ui 依赖项。
关于java - 无法推断基本网址。这在使用动态 servlet 注册或 API 位于 API 网关 swagger 2.10.5 之后时很常见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62743679/