首页 > 其他 > 详细

使用swagger管理接口

时间:2017-02-17 17:13:51      阅读:409      评论:0      收藏:0      [点我收藏+]

swagger 配置
1.pom 增加jar包依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
2.MVC config 增加 <mvc:default-servlet-handler/>
在resource下面的mvc-config.xml

3.新建一个swagger类
@EnableWebMvc
@ComponentScan(basePackages={"com.mosai.vliveshow.api.app.interfaces.controller"})
@Configuration
@EnableSwagger2
public class Swagger2 extends WebMvcConfigurationSupport{

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.mosai.vliveshow.api.app.interfaces.controller"))
.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("程序猿DD")
.version("1.0")
.build();
}

}
4.修改待扫描的路径
5.配置服务器
6.swagger UI的地址http://localhost:8080/vliveshow-api-app/swagger-ui.html#/

使用swagger管理接口

原文:http://www.cnblogs.com/jier888/p/6410322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!