Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
4f29e256
Commit
4f29e256
authored
Apr 26, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0.0
parent
67b8c593
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletions
+41
-1
api-server/src/main/java/com/zq/api/config/FeignConfig.java
+39
-0
api-server/src/main/java/com/zq/api/feign/CmsFeign.java
+2
-1
No files found.
api-server/src/main/java/com/zq/api/config/FeignConfig.java
0 → 100644
View file @
4f29e256
package
com
.
zq
.
api
.
config
;
import
com.zq.common.http.HttpRequestUtils
;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Enumeration
;
@Configuration
public
class
FeignConfig
{
/**
* 解决fein远程调用丢失请求头
*
* @return
*/
@Bean
public
RequestInterceptor
requestInterceptor
()
{
return
new
RequestInterceptor
()
{
@Override
public
void
apply
(
RequestTemplate
template
)
{
HttpServletRequest
request
=
HttpRequestUtils
.
getRequest
();
template
.
header
(
"X-App-Token"
,
request
.
getParameter
(
"token"
));
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
if
(
headerNames
!=
null
)
{
while
(
headerNames
.
hasMoreElements
())
{
String
name
=
headerNames
.
nextElement
();
String
values
=
request
.
getHeader
(
name
);
template
.
header
(
name
,
values
);
}
}
}
};
}
}
api-server/src/main/java/com/zq/api/feign/CmsFeign.java
View file @
4f29e256
package
com
.
zq
.
api
.
feign
;
import
com.zq.api.config.FeignConfig
;
import
com.zq.common.vo.ResultVo
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -7,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
java.util.Map
;
@FeignClient
(
name
=
"CMS-SERVER"
)
//指定调用哪个微服务
@FeignClient
(
name
=
"CMS-SERVER"
,
configuration
=
FeignConfig
.
class
)
//指定调用哪个微服务
@RequestMapping
(
"/cms"
)
public
interface
CmsFeign
{
...
...
Write
Preview
Markdown
is supported
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