Jef*_*ook 6 spring swagger microservices api-gateway
我已经去了为什么 springfox-swagger2 UI 告诉我“无法推断基本 url”。并且在使用 Spring Boot 配置 Swagger并且根本不使用 Spring Security 时获得意外结果,对于每个服务,我使用的是@EnableSwagger2注释。
我正在关注链接中的教程:https : //dzone.com/articles/quick-guide-to-microservices-with-spring-boot-20-e并gateway-service用于项目运行而不是proxy-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}
Run Code Online (Sandbox Code Playgroud)
OrganizationApplication.java 和所有其他服务都是这样实现的。
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7424 次 |
| 最近记录: |