SpringBoot集成Swagger3
应用场景
在开发时,我们经常会面对对接口的测试。而 Swagger 是一个在线api框架,能够在线测试我们的api接口。同时是支持RESTfui 风格接口测试。
依赖导入
| 12
 3
 4
 5
 6
 
 | <dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-boot-starter</artifactId>
 <version>3.0.0</version>
 </dependency>
 
 | 
Config 配置类
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 
 | @Configuration@EnableOpenApi
 public class swaggerConfig {
 
 
 
 
 
 
 
 @Bean
 public Docket restApi() {
 return new Docket(DocumentationType.SWAGGER_2)
 .groupName("标准接口")
 .apiInfo(apiInfo("Spring Boot中使用Swagger3构建RESTful APIs", "1.0"))
 .useDefaultResponseMessages(true)
 .forCodeGeneration(false)
 .select()
 .apis(RequestHandlerSelectors.basePackage("com.shawni.manager.controller"))
 .paths(PathSelectors.any())
 .build();
 }
 
 
 
 
 
 private ApiInfo apiInfo(String title, String version) {
 return new ApiInfoBuilder()
 .title(title)
 .description("Swagger3")
 .termsOfServiceUrl("https://Shawnicsc.github.io")
 .contact(new Contact("shawni's Blog", "https://Shawnicsc.github.io", "shawni@firefox.com"))
 .version(version)
 .build();
 }
 }
 
 |