Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway swagger 2.10.5

Viewed 2055

Trying to configure swagger 2.10.5 with spring boot Rest API but keep getting the error Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway

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'
}

Config File

@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();
    }
}

ApplicationFile

@SpringBootApplication
public class MeroRentalRestApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(MeroRentalRestApiApplication.class, args);
    }
}

SpringFoxConfig and application are in the same package

Tried lot of the solution from the

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/

1 Answers

If anyone is using 2.10.5 and facing same issue then in my case I was able to resolve it by adding below dependency springfox-spring-webmvc with same version(2.10.5). I already had springfox-swagger2 and springfox-swagger-ui dependencies in my pom.xml file.

I got clue from https://github.com/springfox/springfox/issues/3336

Related