在这个项目中,我使用了Swagger2生成我们的接口文档,把需要的包导入之后,只需要简单配置下就可以: 在pom.xml文件导入如下包: `
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.14</version>
<scope>compile</scope>
</dependency>
然后就是配置文件Swagger2Config的代码:
/**
* swagger2配置类
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi(){//规定扫描那些包下面的接口生成swagger文档
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.hhk.server.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("my-project-接口文档")
.description("my-project-接口文档")
.contact(new Contact("密探探长","http:localhost:8081/doc.html","9xxx.qq.com"))
.version("0.0.1")
.build();
}
}
至此我们就配置好了Swagger接口文档了。