无法推断基本网址.当使用动态servlet注册或API位于API网关后面时,这很常见. [英] Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway
问题描述
我已经去过和
I already went Why does springfox-swagger2 UI tell me "Unable to infer base url." and Getting an unexpected result while configuring Swagger with Spring Boot and not using Spring Security at all and for each service, I am using @EnableSwagger2
annotations.
我正在通过链接关注本教程: https://dzone.com/articles/quick-guide-to-microservices-with-spring-boot-20-e ,并使用gateway-service
代替proxy-service
来运行项目.
I'm following tutorial from link: https://dzone.com/articles/quick-guide-to-microservices-with-spring-boot-20-e and using gateway-service
for the project to run instead of proxy-service
.
gateway-service.yml
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/(?<path>.*), /$\{path}
- id: department-service
uri: lb://department-service
predicates:
- Path=/department/**
filters:
- RewritePath=/department/(?<path>.*), /$\{path}
- id: organization-service
uri: lb://organization-service
predicates:
- Path=/organization/**
filters:
- RewritePath=/organization/(?<path>.*), /$\{path}
OrganizationApplication.java和所有其他服务的实现完全与此相同.
OrganizationApplication.java and all other services are implemented exactly like this.
@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;
}
}
推荐答案
将springfox-swagger2和springfox-swagger-ui依赖项升级到2.9.2版本.
Upgrade your springfox-swagger2 and springfox-swagger-ui dependencies to 2.9.2 version.
这篇关于无法推断基本网址.当使用动态servlet注册或API位于API网关后面时,这很常见.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!