商户系统配置 knife4j
This commit is contained in:
parent
8f301dcfa7
commit
1fd61f3e62
|
|
@ -106,6 +106,12 @@
|
|||
<artifactId>spring-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<!-- 作为可执行jar -->
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.jeequan.jeepay.mch.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,22 @@ public class JeepayMchApplication {
|
|||
return paginationInterceptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能描述: API访问地址: http://localhost:9218/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.mch.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;
|
||||
|
|
@ -34,9 +35,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue