Spring boot结合swagger自动生成api文档
2017-05-31 16:19
1201 查看
首先需要在工程中加入以下依赖:
版本随意。
然后创建自己的swagger类:@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.myweb.Controller"))//注解1
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.description("更多Spring Boot相关文章请关注:http://blog.didispace.com/")
.termsOfServiceUrl("http://blog.didispace.com/")
.contact("作者")
.version("1.0")
.build();
}
}如上代码所示,通过
注解1是你的接口所在的文件夹(包),
启动springboot然后访问http://localhost:8080/swagger-ui.html就可以了,注意自己有没有改端口。
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version> </dependency>
版本随意。
然后创建自己的swagger类:@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.myweb.Controller"))//注解1
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.description("更多Spring Boot相关文章请关注:http://blog.didispace.com/")
.termsOfServiceUrl("http://blog.didispace.com/")
.contact("作者")
.version("1.0")
.build();
}
}如上代码所示,通过
@Configuration注解,让Spring来加载该类配置。再通过
@EnableSwagger2注解来启用Swagger。
注解1是你的接口所在的文件夹(包),
启动springboot然后访问http://localhost:8080/swagger-ui.html就可以了,注意自己有没有改端口。
相关文章推荐
- springboot结合swagger自动生成接口文档
- SwaggerUI自动生成API文档(SwaggerUI+SpringBoot)
- Spring Boot如何让Web API自动生成文档,并解决swagger-annotations的API注解description属性废弃的问题
- 使用Spring Boot&Swagger快速构建REST API并生成优美的API文档
- springboot+springfox+Swagger 实现项目的restful文档的自动生成
- SpringBoot 自动生成API文档
- Springboot | SpringBoot 微服务整合Swagger生成API文档
- spring-boot整合swagger生成在线api文档
- 使用 SpringBoot + Swagger 生成接口 API 文档
- SpringBoot&Swagger构建REST API并生成API文档
- Swagger2 生成 Spring Boot API 文档
- SpringBoot:番外篇SpringBoot+Swagger生成可视图的API文档
- SpringBoot + mybatis + Swagger快速构建REST API并生成优美的API文档
- spring boot 中使用swagger 来自动生成接口文档
- spring boot rest接口自动生成文档(包含swagger)
- Swagger自动接口文档生成框架————springboot整合swagger总结
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
- 使用Swagger在SpringBoot项目中管理API文档(使用Oauth2)
- Spring MVC 集成 Swagger,API文档自动生成~
- API文档自动生成,Swagger的配置