Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Jeepay
Commits
1fd61f3e
Commit
1fd61f3e
authored
Jun 13, 2023
by
terrfly
Browse files
商户系统配置 knife4j
parent
8f301dcf
Changes
4
Hide whitespace changes
Inline
Side-by-side
jeepay-merchant/pom.xml
View file @
1fd61f3e
...
...
@@ -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 -->
...
...
jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/bootstrap/JeepayMchApplication.java
View file @
1fd61f3e
...
...
@@ -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
();
}
}
jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/secruity/WebSecurityConfig.java
View file @
1fd61f3e
...
...
@@ -142,7 +142,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
"/**/*.mp4"
//支持mp4格式的文件匿名访问
)
.
antMatchers
(
"/api/anon/**"
//匿名访问接口
"/api/anon/**"
,
//匿名访问接口
"/swagger-resources/**"
,
"/v2/api-docs/**"
// swagger相关
);
}
...
...
jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/web/ApiResBodyAdvice.java
View file @
1fd61f3e
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment