目录
一.引入依赖;
<!-- 引入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>
二.配置swagger
@Configuration
@EnableSwagger2
public class Swagger2Config {
/**
* 创建swagger对象:
*
* @return
*/
@Bean
public Docket mapRestApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("地图坐标转化APIs")
.apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.example.microservice.http.controller.server.map"))
.paths(PathSelectors.any())
.build();
}
/**
* 设置api信息
* title:swagger题目
* description:描述
* cotact:创建者
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("微服务API")
.description("springboot框架小服务")
.contact(new Contact("yourname",null ,"xxx@qq.com"))
.version("1.0")
.build();
}
}
groupName:当出现多个服务时候,可以用来进行分组
三.界面展示
四:使用swagger注解
@API