SpringCloud-Zuul整合微服務所有API接口


Zull整合Swagger管理微服務所有API

1、各微服務項目引入依賴

<!-- swagger-spring-boot -->
<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.7.0.RELEASE</version>
</dependency>

2、application.xml配置掃包范圍

swagger:
  base-package: api所在的包地址

3、項目啟動加上注解@EnableSwagger2Doc

4、在對應的API類文件上加上@Api("當前API文檔說明"),對應API方法上加@ApiOperation("接口說明");@ApiImplicitParam

5、網關中Swagger配置類

@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        resources.add(swaggerResource("wegns", "/wegns-a/v2/api-docs", "2.0"));
        resources.add(swaggerResource("redis-proxy", "/redis-util/v2/api-docs", "2.0"));
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM