在ruoyi-cloud中使用knife4j
在ruoyi pom.xml文件中添加
<!-- swagger增强配置 knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<!--knife4j的UI-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
<version>${knife4j.version}</version> </dependency>
在ruoyi-common-swagger,pom.xml文件中添加
<!--swagger增强 knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
在ruoyi-gateway,pom.xml文件中 注释原来引入的swagger依赖,增加knife4j依赖
<!-- Swagger -->
<!-- <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
</dependency>
在nacos配置中心的ruoyi-gateway-dev.yml,文件中添加配置
#knife4j配置
knife4j:
basic:
enable: false
enable: true
#增强配置
setting:
enableSwaggerModels: true
enableDocumentManage: true
enableHost: true
enableHostText: http://localhost
enableRequestCache: false
enableFilterMultipartApis: true
enableFilterMultipartApiMethodType: POST
language: zh-CN
完成上面的配置后 启动RuoYiGatewayApplication服务访问 http://localhost:8080/doc.html 即可看到接口文档页面。启动对应模块即可在接口文档中查看模块的接口信。
注:
1,需要访问的服务需要在ruoyi-gateway-dev.yml中的spring.cloud.gateway.routes中配置相关参数。
2,想查看接口信息需要添加对应的注解:@ApiModelProperty,@ApiModel,@Api,@ApiOperation等。