添加Knife4j 相关配置;
This commit is contained in:
parent
968cbbc4dc
commit
336278be5b
|
|
@ -85,6 +85,11 @@
|
|||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 所以项目依赖swagger注解包 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import com.jeequan.jeepay.core.utils.JsonKit;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/*
|
||||
* 接口返回对象
|
||||
*
|
||||
|
|
@ -33,7 +35,7 @@ import lombok.Data;
|
|||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ApiRes {
|
||||
public class ApiRes<T> implements Serializable {
|
||||
|
||||
/** 业务响应码 **/
|
||||
private Integer code;
|
||||
|
|
@ -42,7 +44,7 @@ public class ApiRes {
|
|||
private String msg;
|
||||
|
||||
/** 数据对象 **/
|
||||
private Object data;
|
||||
private T data;
|
||||
|
||||
/** 签名值 **/
|
||||
private String sign;
|
||||
|
|
@ -58,7 +60,7 @@ public class ApiRes {
|
|||
}
|
||||
|
||||
/** 业务处理成功 **/
|
||||
public static ApiRes ok(Object data){
|
||||
public static <T> ApiRes<T> ok(T data){
|
||||
return new ApiRes(ApiCodeEnum.SUCCESS.getCode(), ApiCodeEnum.SUCCESS.getMsg(), data, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,12 @@
|
|||
<artifactId>jeepay-sdk-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.jeequan.jeepay.mgr.bootstrap;
|
|||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
|
@ -27,6 +28,11 @@ import org.springframework.context.annotation.ComponentScan;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -39,6 +45,7 @@ import java.util.Arrays;
|
|||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@EnableSwagger2WebMvc
|
||||
@MapperScan("com.jeequan.jeepay.service.mapper") //Mybatis mapper接口路径
|
||||
@ComponentScan(basePackages = "com.jeequan.jeepay.*") //由于MainApplication没有在项目根目录, 需要配置basePackages属性使得成功扫描所有Spring组件;
|
||||
@Configuration
|
||||
|
|
@ -81,4 +88,23 @@ public class JeepayMgrApplication {
|
|||
return paginationInterceptor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述: API访问地址: http://localhost:9217/doc.html
|
||||
*
|
||||
* @Return: springfox.documentation.spring.web.plugins.Docket
|
||||
* @Author: terrfly
|
||||
* @Date: 2023/6/13 15:04
|
||||
*/
|
||||
@Bean(value = "dockerBean")
|
||||
public Docket dockerBean() {
|
||||
return new Docket(DocumentationType.SWAGGER_2) //指定使用Swagger2规范
|
||||
.apiInfo(new ApiInfoBuilder().version("1.0").build()) //描述字段支持Markdown语法
|
||||
.groupName("运营平台") //分组名称
|
||||
.select() // 配置: 如何扫描
|
||||
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 只扫描: ApiOperation 注解文档。 也支持配置包名、 路径等扫描模式。
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
|
|||
"/**/*.mp4" //支持mp4格式的文件匿名访问
|
||||
)
|
||||
.antMatchers(
|
||||
"/api/anon/**" //匿名访问接口
|
||||
"/api/anon/**", //匿名访问接口
|
||||
"/swagger-resources/**","/v2/api-docs/**" // swagger相关
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
package com.jeequan.jeepay.mgr.web;
|
||||
|
||||
import com.jeequan.jeepay.core.utils.ApiResBodyAdviceKit;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
|
|
@ -33,9 +34,20 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
|||
@ControllerAdvice
|
||||
public class ApiResBodyAdvice implements ResponseBodyAdvice {
|
||||
|
||||
/** 注入 是否开启 knife4j **/
|
||||
@Value("${knife4j.enable}")
|
||||
private boolean knife4jEnable = false;
|
||||
|
||||
/** 判断哪些需要拦截 **/
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType, Class converterType) {
|
||||
|
||||
// springfox.documentation.swagger.web.ApiResourceController -- /swagger-resources
|
||||
// springfox.documentation.swagger2.web.Swagger2ControllerWebMvc -- /v2/api-docs
|
||||
if(knife4jEnable && returnType.getMethod().getDeclaringClass().getName().startsWith("springfox.documentation.swagger")){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
15
pom.xml
15
pom.xml
|
|
@ -184,6 +184,21 @@
|
|||
<version>${jaxb-api.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger注解包 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.6.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
|
|
|||
Loading…
Reference in New Issue