对于分布式项目首先将swagger的maven的依赖引入接口子项目
<dependencies>
<!-- 生成接口文档 -->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
</dependencies>
然后在需要打印日志的子项目中的yml中配置
####swagger相关配置
####访问地址:127.0.0.1:8200/swagger-ui.html
swagger:
base-package: com.qut.weixin.service
title: SpringCloud2.x构建微服务电商项目-微信服务接口
description: 本项目为自学springboot+springcloud项目
version: 1.1
terms-of-service-url: www.xbnzs.cn
contact:
name: yujun.wang
email: yujun.wang@hand-china.com
启动类上添加注解
@EnableSwagger2Doc
对于springcloud中将swagger加入网关zuul中第一步需要引入,maven依赖,依赖上面给出
然后启动网关和配置类如下:
@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
@EnableSwagger2Doc
public class AppGateWay {
public static void main(String[] args) {
SpringApplication.run(AppGateWay.class, args);
}
// 添加文档来源
@Component
@Primary
class DocumentationConfig implements SwaggerResourcesProvider {
@Override
public List<SwaggerResource> get() {
List resources = new ArrayList<>();
// app-qut-order
//网关获取服务别名获取远程服务的Swagger接口
resources.add(swaggerResource("app-qut-member", "/app-qut-member/v2/api-docs", "2.0"));
resources.add(swaggerResource("app-qut-weixin", "/app-qut-weixin/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;
}
}
}