3

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/

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • maybe try to use annotation `@EnableSwagger2`? or you could change dependency to a new swagger `org.springdoc:springdoc-openapi-ui` – Vasyl Sarzhynskyi Jul 05 '20 at 19:11
  • @VasylSarzhynskyi I can't use EnableSwagger2 for version swagger 2.10.5. It doesn't contain. – San Jaisy Jul 06 '20 at 02:07
  • This solve my issue https://stackoverflow.com/questions/62754998/whitelabel-error-page-swagger-this-application-has-no-explicit-mapping-for-err?noredirect=1#comment110978358_62754998 – San Jaisy Jul 08 '20 at 00:57

1 Answers1

-1

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

Prakash Boda
  • 808
  • 7
  • 21