当前位置: 代码迷 >> 综合 >> spring boot整合swagger2+caspar-chen / swagger-ui-layer
  详细解决方案

spring boot整合swagger2+caspar-chen / swagger-ui-layer

热度:121   发布时间:2023-09-19 18:04:36.0

采用swagger2配置接口文档

1 pom依赖

      <!--swagger配置--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.7.0</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.7.0</version></dependency><dependency><groupId>com.github.caspar-chen</groupId><artifactId>swagger-ui-layer</artifactId><version>1.1.3</version></dependency><dependency><groupId>com.github.xiaoymin</groupId><artifactId>swagger-bootstrap-ui</artifactId><version>1.9.6</version></dependency><!--swagger2 end-->

2 配置swagger2Config.java

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
// @Profile({"dev", "stage"})
public class SwaggerConfig {@Beanpublic Docket ProductApi() {return new Docket(DocumentationType.SWAGGER_2).genericModelSubstitutes(DeferredResult.class).useDefaultResponseMessages(false).forCodeGeneration(false).pathMapping("/").select().build().apiInfo(productApiInfo());}private ApiInfo productApiInfo() {ApiInfo apiInfo = new ApiInfo("XXX系统数据接口文档","文档描述。。。","1.0.0","API TERMS URL","联系人邮箱","license","license url");return apiInfo;}
}

3 浏览器访问

http://localhost:${port}/swagger-ui.html
或者
http://localhost:${port}/doc.html
  相关解决方案