Swagger配置

匿名 (未验证) 提交于 2019-12-03 00:27:02

1、在pom.xml里面添加

<!-- swagger --> <dependency>    <groupId>io.springfox</groupId>    <artifactId>springfox-swagger2</artifactId>    <version>2.2.2</version> </dependency> <!-- swagger-ui --> <dependency>    <groupId>io.springfox</groupId>    <artifactId>springfox-swagger-ui</artifactId>    <version>2.2.2</version> </dependency>

2、在Application文件同级添加Swagger2类

package com.boot.myspring; import io.swagger.annotations.ApiOperation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;  @Configuration @EnableSwagger2 public class Swagger2 {     @Bean     public Docket swaggerSpringMvcPlugin() {         return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();     } }

3、Controller类上加注解


4、接口上加注解

1)传参


2)不传参


5、访问http://localhost:8080/swagger-ui.html


6、如果找不到接口在Application中加上扫描


文章来源: Swagger配置
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!