标签:return depend create public frame api文档 inf 集成swagger des
<!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency>
import org.springframework.context.annotation.Bean;
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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @Auther: lanhaifeng
* @Date: 2019/6/3 0003 10:51
* @Description:
* @statement: 百度一下
*/
@Configuration
@EnableSwagger2
public class Swagger2 {
//swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//扫描的controller包
.apis(RequestHandlerSelectors.basePackage("com.baidu.business.core.controller"))
.paths(PathSelectors.any())
.build();
}
//构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("百度客户端 Swagger2 构建RESTful API")
//创建人
.contact(new Contact("baidu", "http://www.baidu.com", "@emall").toString())
//版本号
.version("1.0")
//描述
.description("API 描述")
.build();
}
}
标签:return depend create public frame api文档 inf 集成swagger des
原文地址:https://www.cnblogs.com/zeussbook/p/10966504.html