使用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#/服務器

相關文章
相關標籤/搜索