首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swagger网关MicroService聚合

Swagger网关MicroService聚合
EN

Stack Overflow用户
提问于 2018-03-15 06:27:20
回答 1查看 5.1K关注 0票数 5

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

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

我们已经整合的临时解决方案是,为网关服务中的每个微服务复制Swagger类。做这件事的正确方式是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-23 05:58:20

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

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

代码语言:javascript
复制
<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>

我的主修课是这样的

代码语言:javascript
复制
 @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文档创建了聚合器。

代码语言:javascript
复制
@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如下所示

代码语言:javascript
复制
...
server.port=8001

zuul.routes.cust.path=/cust/**
zuul.routes.cust.url=http://1.1.1.2:8002/cust-service/
...
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49292843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档