title: Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway
body: <p>I already went <a href="https://stackoverflow.com/questions/47425048/why-does-springfox-swagger2-ui-tell-me-unable-to-infer-base-url?rq=1">Why does springfox-swagger2 UI tell me &quot;Unable to infer base url.&quot;</a> and <a href="https://stackoverflow.com/questions/46520149/getting-an-unexpected-result-while-configuring-swagger-with-spring-boot">Getting an unexpected result while configuring Swagger with Spring Boot</a> and not using Spring Security at all and for each service, I am using <code>@EnableSwagger2</code> annotations.</p>
  
  <p>I'm following tutorial from link: <a href="https://dzone.com/articles/quick-guide-to-microservices-with-spring-boot-20-e" rel="noreferrer">https://dzone.com/articles/quick-guide-to-microservices-with-spring-boot-20-e</a> and using <code>gateway-service</code> for the project to run instead of <code>proxy-service</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/b95ws.png" rel="noreferrer"><img src="https://i.stack.imgur.com/b95ws.png" alt="enter image description here"></a></p>
  
  <p><strong>gateway-service.yml</strong></p>
  
  <pre><code>server:
    port: 8060
  
  eureka:
    client:
      serviceUrl:
        defaultZone: http://localhost:8061/eureka/
  
  logging:
    pattern: 
      console: "%d{yyyy-MM-dd HH:mm:ss} ${LOG_LEVEL_PATTERN:-%5p} %m%n"
  
  spring:
    cloud:
      gateway:
        discovery:
          locator:
            enabled: true
        routes:
        - id: employee-service
          uri: lb://employee-service
          predicates:
          - Path=/employee/**
          filters:
          - RewritePath=/employee/(?&lt;path&gt;.*), /$\{path}
        - id: department-service
          uri: lb://department-service
          predicates:
          - Path=/department/**
          filters:
          - RewritePath=/department/(?&lt;path&gt;.*), /$\{path}
        - id: organization-service
          uri: lb://organization-service
          predicates:
          - Path=/organization/**
          filters:
          - RewritePath=/organization/(?&lt;path&gt;.*), /$\{path}
  </code></pre>
  
  <p>OrganizationApplication.java and all other services are implemented exactly like this.</p>
  
  <pre><code>@SpringBootApplication
  @EnableDiscoveryClient
  @EnableFeignClients
  @EnableSwagger2
  public class OrganizationApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(OrganizationApplication.class, args);
      }
  
      @Bean
      public Docket swaggerApi() {
          return new Docket(DocumentationType.SWAGGER_2)
                  .select()
                      .apis(RequestHandlerSelectors.basePackage("pl.piomin.services.organization.controller"))
                      .paths(PathSelectors.any())
                  .build()
                  .apiInfo(new ApiInfoBuilder().version("1.0").title("Organization API").description("Documentation Organization API v1.0").build());
      }
  
      @Bean
      OrganizationRepository repository() {
          OrganizationRepository repository = new OrganizationRepository();
          repository.add(new Organization("Microsoft", "Redmond, Washington, USA"));
          repository.add(new Organization("Oracle", "Redwood City, California, USA"));    
          return repository;
      }
  }
  </code></pre>