使用swagger管理接口

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{html

@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();
}spring

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();
}api

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

相关文章
相关标签/搜索