Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
55a28e13
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
55a28e13
编写于
8月 06, 2021
作者:
G
Gadfly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(youlai-common): 增加feign拦截器,fix #32
上级
87cde339
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
0 deletion
+62
-0
youlai-common/common-web/pom.xml
youlai-common/common-web/pom.xml
+4
-0
youlai-common/common-web/src/main/java/com/youlai/common/web/config/FeignConfig.java
...c/main/java/com/youlai/common/web/config/FeignConfig.java
+57
-0
youlai-common/common-web/src/main/resources/META-INF/spring.factories
...n/common-web/src/main/resources/META-INF/spring.factories
+1
-0
未找到文件。
youlai-common/common-web/pom.xml
浏览文件 @
55a28e13
...
...
@@ -49,6 +49,10 @@
<artifactId>
dozer-core
</artifactId>
</dependency>
<dependency>
<groupId>
io.github.openfeign
</groupId>
<artifactId>
feign-core
</artifactId>
</dependency>
</dependencies>
</project>
youlai-common/common-web/src/main/java/com/youlai/common/web/config/FeignConfig.java
0 → 100644
浏览文件 @
55a28e13
package
com.youlai.common.web.config
;
import
feign.RequestInterceptor
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Enumeration
;
/**
* Feign相关配置类
*
* @author Gadfly
* @since 2021-08-06 9:47
*/
@Configuration
public
class
FeignConfig
{
/**
* 让DispatcherServlet向子线程传递RequestContext
*
* @param servlet servlet
* @return 注册bean
*/
@Bean
public
ServletRegistrationBean
<
DispatcherServlet
>
dispatcherRegistration
(
DispatcherServlet
servlet
)
{
servlet
.
setThreadContextInheritable
(
true
);
return
new
ServletRegistrationBean
<>(
servlet
,
"/**"
);
}
/**
* 覆写拦截器,在feign发送请求前取出原来的header并转发
*
* @return 拦截器
*/
@Bean
public
RequestInterceptor
requestInterceptor
()
{
return
(
template
)
->
{
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
//获取请求头
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
if
(
headerNames
!=
null
)
{
while
(
headerNames
.
hasMoreElements
())
{
String
name
=
headerNames
.
nextElement
();
String
values
=
request
.
getHeader
(
name
);
//将请求头保存到模板中
template
.
header
(
name
,
values
);
}
}
};
}
}
youlai-common/common-web/src/main/resources/META-INF/spring.factories
浏览文件 @
55a28e13
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.youlai.common.web.config.WebMvcConfig,\
com.youlai.common.web.config.FeignConfig,\
com.youlai.common.web.exception.GlobalExceptionHandler,\
com.youlai.common.web.aspect.LoginLogAspect
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录