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#/