介绍
- 这是我配置swagger的一个补充项
- knife4j 提供的聚合项目
针对多个springboot 的单体项目的文档聚合
-
引入依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-aggregation-spring-boot-starter</artifactId><version>2.0.8</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
开始配置
-
application.yml ```yaml server: port: 19081 knife4j: enableAggregation: true cloud: enable: true routes:
- name: 测试分组1uri: knife4j.xiaominfo.comlocation: /v2/api-docs?group=2.X版本- name: 测试分组2uri: knife4j.xiaominfo.comlocation: /v2/api-docs?group=3.默认接口- name: 测试分组3uri: 192.168.0.51:8080location: /api/multistage/v2/api-docs?group=version2.0
<a name="YqswM"></a># 示例测试- 启动访问 127.0.0.1:8080/doc.html- <a name="NH3mr"></a># 注意事项1. 项目的编码集,由于我配中有中文,项目确实GBK的编码,导致第一次测试失败,页面加载不了接口数据2. 配置 `uri` 注意,只需要 ip+port ,要不要在后面加上后缀,根据需求决定,加上接口会多一重路径1. 项目使用 soul网关 统一入口之后,参考一下配置```yaml# 网关IP端口xxxGateway:urlPort: 192.168.0.51:9195knife4j:enableAggregation: truecloud:enable: trueroutes:- name: 内置用户uri: ${xxxGateway.urlPort}/smartUser # 网关IP端口+网关前缀location: /user/v2/api-docs?group=version2.0 # 详细地址 项目真实地址 /smartUser + /user/v2/api-docs?group=version2.0servicePath: /smartAppointment # 该属性是最终在Ui中展示的接口前缀属性(跟随网关的前缀)- name: 全文检索uri: ${xxxGateway.urlPort}/smartSolrlocation: /solr/v2/api-docs?group=version2.0 # 详细地址servicePath: /smartAppointment- name: 主体项目uri: ${xxxGateway.urlPort}/smartAppointmentlocation: /mian/v2/api-docs?group=version2.0 # 详细地址servicePath: /smartMian
- 第二步配置好的同时,
location前面要配置项目的访问前缀,要不然接口会报错
