Swagger2 是一个为RESTful web服务生成API在线文档的开源项目,它通过web浏览器,提供一个测试RESTful web service的用户界面。
为了在SpringBoot项目中使用到Swagger2,你需要添加下面的依赖:
1 | <dependency> |
然后在SpringBoot主程序类上添加@EnableSwagger2注解开启Swagger2支持。其次,创建一个Docket Bean来配置Swagger2。案例如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18package com.restfulapio.demo;
2
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.restfulapio.demo.controller")).build();
}
}

评论加载中