1.pom文件导入依赖
<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>
2.书写配置类SwaggerConfig
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("(?!/error.*).*"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfo(
"机器人系统Api文档",
"SpringBoot+Vue",
"v1.0",
"",
new Contact("周一", "http://www.zybot.top", null),
"",
"",
new ArrayList()
);
}
}
3.访问swagger-ui
项目路径 + swagger-ui.html#/
例:http://127.0.0.1:9999/bot-admin/
即:http://127.0.0.1:9999/bot-admin/swagger-ui.html#/
4.线上测试
Swagger UI
![Swagger UI](https://i-blog.csdnimg.cn/blog_migrate/dd7d7806b950346b0bcb3ce1737b916c.png#pic_center)