依赖:
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
配置:
@EnableSwagger2
@Configuration
public class MySwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//标题
.title("Spring Boot 中使用 Swagger2 构建 RESTful APIs")
//简介
.description("hello swagger")
//服务条款
.termsOfServiceUrl("1. xxx\n2. xxx\n3. xxx")
//作者个人信息
.contact(new Contact("admin", "https://blog.csdn.net/A2735856944", "2735856944@qq.com"))
//版本
.version("1.0")
.build();
}
}
Swagger 访问地址:
springboot工程格式如下
http://127.0.0.1:8087/swagger-ui.html
非springboot工程加个自己项目名
http://127.0.0.1:8087/xxx/swagger-ui.html