Swagger3相较于2,可谓是更加简单粗暴,只需两部就能搞定引入,比2银杏化了很多很多,直接开始:
引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
配置类
@Configuration
@EnableOpenApi
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.enable(true)
.groupName("api")
.select()
.apis(RequestHandlerSelectors.basePackage("cc.han0.**")) // 控制器所在包
.build();
}
@SuppressWarnings("all")
public ApiInfo apiInfo(){
return new ApiInfo(
"标题",
"描述",
"v1.0", // 版本
"weihan0@foxmail.com", //开发者团队的邮箱
"Han0",
"Apache 2.0", //许可证
"http://www.apache.org/licenses/LICENSE-2.0" //许可证链接
);
}
}
这样就能直接访问http://localhost:port/swagger-ui/,查看swagger生成的接口文档了,推荐配合ApiFox来使用