Maven中引入Jar包

由于是springfox-swagger的增强UI包,所以基础功能依然依赖Swagger,springfox-swagger的jar包必须引入

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-swagger2</artifactId>
  4. <version>2.9.2</version>
  5. </dependency>

然后引入SwaggerBootstrapUi的jar包

  1. <dependency>
  2. <groupId>com.github.xiaoymin</groupId>
  3. <artifactId>swagger-bootstrap-ui</artifactId>
  4. <version>${lastVersion}</version>
  5. </dependency>

编写Swagger2Config配置文件

Swagger2Config配置文件如下:

  1. @Configuration
  2. @EnableSwagger2
  3. public class SwaggerConfiguration {
  4. @Bean
  5. public Docket createRestApi() {
  6. return new Docket(DocumentationType.SWAGGER_2)
  7. .apiInfo(apiInfo())
  8. .select()
  9. .apis(RequestHandlerSelectors.basePackage("com.bycdao.cloud"))
  10. .paths(PathSelectors.any())
  11. .build();
  12. }
  13. private ApiInfo apiInfo() {
  14. return new ApiInfoBuilder()
  15. .title("swagger-bootstrap-ui RESTful APIs")
  16. .description("swagger-bootstrap-ui")
  17. .termsOfServiceUrl("http://localhost:8999/")
  18. .contact("developer@mail.com")
  19. .version("1.0")
  20. .build();
  21. }
  22. }

访问地址

swagger-bootstrap-ui默认访问地址是:http://${host}:${port}/doc.html