1、整合springfox
pom.xml
<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>
配置,启动类上加@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build()
//接口信息
.apiInfo(apiInfo())
//全局参数
.globalOperationParameters(getGlobalOperationParameters())
//全站统一参数token
.securitySchemes(authToken())
;
}
//接口信息配置
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("秋名山见")
.description("秋名山见,详细信息......")
.version("9.0")
.license("The Apache License")
.licenseUrl("http://www.baidu.com")
.build();
}
}
2、整合springboot-starter-swagger
pom.xml
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
配置application.yml(空格1-3),启动类上加@EnableSwagger2Doc
swagger:
title: demoApi
basePackage: com.xiaoyu
description: no description
version: 2.0