spring boot使用Swagger
Posted 江州益彤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot使用Swagger相关的知识,希望对你有一定的参考价值。
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
配置类SwaggerConfig内容
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig
@Bean //作为bean纳入spring容器
public Docket api()
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//.paths(PathSelectors.any())
.apis(RequestHandlerSelectors.basePackage("com.ermao.controller"))
.build();
private ApiInfo apiInfo()
return new ApiInfoBuilder()
.title("API接口文档")
.description("API接口文档,及相关接口的说明")
.version("v1.0.0")
.build();
使用
http://localhost:8181/swagger-ui.html#/
以上是关于spring boot使用Swagger的主要内容,如果未能解决你的问题,请参考以下文章