java - 无法推断基本网址。这在使用动态 servlet 注册或 API 位于 API 网关 swagger 2.10.5 之后时很常见

标签 java spring spring-boot swagger springfox

尝试使用 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-demos/blob/master/boot-swagger/src/main/java/springfoxdemo/boot/swagger/Application.java

https://github.com/springfox/springfox/issues/2191

https://github.com/springfox/springfox/issues/1996

https://github.com/springfox/springfox/issues/1996

https://springfox.github.io/springfox/docs/current/

最佳答案

如果有人使用 2.10.5 并面临同样的问题,那么就我而言,我可以通过在下面添加具有相同版本 (2.10.5) 的依赖项 springfox-spring-webmvc 来解决它。我的 pom.xml 文件中已经有 springfox-swagger2 和 springfox-swagger-ui 依赖项。

我从 https://github.com/springfox/springfox/issues/3336 得到线索

关于java - 无法推断基本网址。这在使用动态 servlet 注册或 API 位于 API 网关 swagger 2.10.5 之后时很常见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62743679/

相关文章:

java - bundle 的 Java 应用程序被识别为 32 位,它可以在 macOS 10.15 Catalina 下运行吗?

java - Spring 表单命令可以是 Map 吗?

java - Swing 程序中的标准输出会怎样?

java - 如何处理 Camel 中的故障转移负载均衡器故障?

java - 在平等规则之间切换

java - 在 Multi-Tenancy Spring 应用程序中释放空闲数据源?

java - 如何在java代码中安排任务

java - 我们如何在 junit 测试之间清除数据库

java - Spring Mongodb : configure documents to use specific dbs?

java - 为什么 html 页面没有显示在 thymeleaf 中?