spring boot 整合 springfox 实现swagger api文档生成。本项目主要简化整合流程,达到开箱即用,无需更多java代码配置。
引入依赖
<dependency>
<groupId>net.ifok.swagger</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
提示: 1.3.0 有两个ui界面,
http://localhost:8080/doc.html
和http://localhost:8080/swagger-ui.html
<properties>
...其他
<spring-plugin.version>2.0.0.RELEASE</spring-plugin.version>
</properties>
在pom.xml的properties节点添加
<spring-plugin.version>2.0.0.RELEASE</spring-plugin.version>
然后引入<dependency> <groupId>net.ifok.swagger</groupId> <artifactId>swagger-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency>
<dependency>
<groupId>net.ifok.swagger</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-metadata</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-metadata</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
spring.swagger.url-pattern=/**
spring.swagger.packages=
spring.swagger.api-title=API开放文档
spring.swagger.api-description=Api 接口说明
spring.swagger.terms-of-service-url=
spring.swagger.contact.name=联系人名
spring.swagger.contact.email=abc@qq.com
spring.swagger.contact.url=wwww.baidu.com
spring.swagger.license=Apache 2
spring.swagger.license-url=
提示:
spring.swagger.config.packages
与spring.swagger.config.url-pattern
可以只选择其中一个配置,如果两个同时配置则回取两个的并集。
#A组
spring.swagger.group.aaa.group-name=A组名称
spring.swagger.group.aaa.url-pattern=/aaa/**
spring.swagger.group.aaa.packages=
spring.swagger.group.aaa.api-title=A分组API
spring.swagger.group.aaa.api-description=A分组API主要用于干xxx
spring.swagger.group.aaa.terms-of-service-url=
spring.swagger.group.aaa.contact.name=联系人名
spring.swagger.group.aaa.contact.email=abc@qq.com
spring.swagger.group.aaa.contact.url=wwww.baidu.com
spring.swagger.group.aaa.license=Apache 2
spring.swagger.group.aaa.license-url=
#B组
spring.swagger.group.bbb.group-name=B组名称
spring.swagger.group.bbb.url-pattern=/bbb/**
spring.swagger.group.bbb.packages=
spring.swagger.group.bbb.api-title=B分组API
spring.swagger.group.bbb.api-description=B分组API主要用于干xxx
spring.swagger.group.bbb.terms-of-service-url=
spring.swagger.group.bbb.contact.name=联系人名
spring.swagger.group.bbb.contact.email=abc@qq.com
spring.swagger.group.bbb.contact.url=wwww.baidu.com
spring.swagger.group.bbb.license=Apache 2
spring.swagger.group.bbb.license-url=
注意:当同时配置了多分组和单分组,单分组将会无效!
Spring 项目的controller类,添加@Api(tags="该controller的处理说明")
@Api(tags = "用户相关操作")
public class UserController {
@ApiOperation("添加用户")
public Object addUser(){
return "success";
}
}
Apache Software License, Version 2.0
https://www.leftso.com/article/793.html