依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
swagger2配置类:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
Docket docket(){
ApiInfo apiInfo = new ApiInfoBuilder()
.description("项目接口测试文档")
.contact(new Contact("吕晔旋", "http://www.baidu.com", "L806291560@163.com"))
.version("v1.0")
.title("API测试文档")
.license("Apache2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.build();
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.fengqing.springbootdemo.controller"))
.build()
.apiInfo(apiInfo);
}
}
访问地址:
http://localhost:8080/swagger-ui.html