對于分布式項目首先将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: [email protected]
啟動類上添加注解
@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;
}
}
}