添加Maven依赖
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency>
添加配置类
@Configuration @EnableSwagger2 @EnableSwaggerBootstrapUI public class SwaggerBootstrapConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.xc.xcspringboot.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("swagger-bootstrap-ui RESTful APIs") .description("swagger-bootstrap-ui") // .termsOfServiceUrl("http://localhost:5050/") .contact("developer@mail.com") .version("1.0") .build(); } }
启动项目
启动项目,访问地址:
http://ip:port/doc.html 即可
该开源项目GitHub地址:
https://github.com/xiaoymin/Swagger-Bootstrap-UI
该开源项目中文文档地址:
https://doc.xiaominfo.com/