1、添加Swagger2依赖
<!-- 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>
2、开启Swagger2(这里选择在配置类开启,可直接在启动类开启)
/**
* Swagger2配置类
*/
@Configuration
@EnableSwagger2 // 开启Swagger2
public class SwaggerConfig {
@Bean
public Docket createDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("标题...")
.description("描述...")
.version("1.0.0")
.build();
}
}
3、访问swagger-ui.html
http://localhost:8086/swagger-ui.html
标签:springfox,SpringBoot,随笔,开启,Swagger2,apiInfo,ui,swagger
From: https://www.cnblogs.com/xiaonuanxin/p/17475809.html