繁体   English   中英

Swagger Gateway MicroService聚合

[英]Swagger Gateway MicroService Aggregation

我正在使用SpringBoot开发一个微服务应用程序。 Gateway Microervice面向公众,它将请求重定向到特定的微服务(运行在不同的主机上)。

现在,我有多个微服务,每个微服务都使用Swagger公开了他们的API。 我们希望为公共客户聚合所有这些API Swagger文档。

我们已经合并的临时解决方案是,只为Gateway Service中的每个微服务复制了Swagger Annotated类。 正确的方法是什么?

我使用了Zuul,这解决了我的问题这就是我的应用程序的部署方式 应用部署

我在我的pom.xml添加了这个

<dependencies>
        ....
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
</dependencies>

我的主要课程看起来像这样

 @EnableZuulProxy
 @SpringBootApplication
 @EnableSwagger2
 public class Application {
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);
     }

    @Bean
    UiConfiguration uiConfig() {
        return new UiConfiguration("validatorUrl", "list", "alpha", "schema",
            UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, 60000L);
    }
 }

我为swagger文档创建了聚合器

@Component
@Primary
@EnableAutoConfiguration
public class SwaggerAggregatorController implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> resources= new ArrayList<>();
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName("cust-service");
        swaggerResource.setLocation("/cust/v2/api-docs");
        swaggerResource.setSwaggerVersion("2.0");

        resources.add(swaggerResource);
        return resources;
    }
}

我可以在这个领域添加更多的微服务。 (可以改进从配置文件中读取)

我的application.properties如下所示

...
server.port=8001

zuul.routes.cust.path=/cust/**
zuul.routes.cust.url=http://1.1.1.2:8002/cust-service/
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM