SpringBoot利用Swagger2构建API文档
pom.xml
<!-- Swagger2 核心依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
Application.java
加注解@EnableSwagger2
@EnableSwagger2
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(SwaggerApplication.class,args) ;
}
}
SwaggerConfig.java
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.swagger.two"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SpringBoot利用Swagger2构建API文档")
.description("this is description")
.termsOfServiceUrl("http://my.description")
.version("version 1.0")
.build();
}
}
访问url
http://127.0.0.1:8080/swagger2/swagger-ui.html