使用swagger2需要在项目中配置SwaggerConfig类,以及导入相关的依赖
<!--swagger2的依赖包-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
接下来配置SwaggerConfig类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("dev")
.apiInfo(webApiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("Swagger2简单测试")
.description("项目名字" +
"接口定义")
.version("1.0")
.contact(new Contact("名字", "http://localhost:8080/swagger-ui.html", ""))
.build();
}
}
启动项目,在网页打开http://localhost:8080/swagger-ui.html
端口号等凭专辑项目需要修改即可,如下图
接口各种信息就在该网页中出现
也可使用第三方软件,即APIFox
创建团队
导入项目或者新建项目
在此页面中新建接口即可,这个软件更加方便,功能齐全。