已解决
SpringCloud-Gateway无法使用Feign服务(2021.X版本)
来自网友在路上 175875提问 提问时间:2023-11-10 07:36:32阅读次数: 75
最佳答案 问答题库758位专家为你答疑解惑
Spring Cloud Gateway 2021.x版本,无法使用Feign调用其他服务接口。
问题原因:
在官网的 issue 里面找到了相关的问题。
How to call another micro-service on GatewayFilterFactory ? · Issue #1090 · spring-cloud/spring-cloud-gateway · GitHubHello, Can you tell me how to call another micro-service on a GatewayFilterFactory? I want to call the authentication micro-service when a request come from user. 1st, I tried to use feign client. but I can not get the ServletRequestAttr...https://github.com/spring-cloud/spring-cloud-gateway/issues/1090
Spring Cloud Gateway 2021.x版本 基于WebFlux实现,使用webclient 替换 feign。
使用案例:
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;/*** @Author: meng* @Description: 权限工具类* @Date: 2023/8/3 15:01* @Version: 1.0*/
@Component
public class AuthUtils {private static Logger logger = LoggerFactory.getLogger(AuthUtils.class);public final static String LB = "lb://";@Autowiredprivate WebClient.Builder webBuilder;public String getAesKeyByAppId(String appId) {JSONObject jsonObject = new JSONObject();jsonObject.put("appId", appId);try {Mono<String> result = webBuilder.baseUrl(LB + "服务名称").build().post().uri("uri").contentType(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "token").bodyValue(jsonObject).retrieve().bodyToMono(String.class);String body = result.toFuture().get();logger.info("body:{}", body);// 处理逻辑...}catch (Exception e) {logger.error("Exception:{}", e);}return null;}}
查看全文
99%的人还看了
相似问题
- flink1.13.6版本的应用程序(maven版)
- 技术分享| gcc版本升级到5.2
- 基于 Glibc 版本升级的 DolphinDB 数据查询性能优化实践
- 解决requests 2.28.x版本SSL错误:证书验证失败
- UE5和UE4版本更新重大改变汇总。
- Docker build报错总结,版本过新大避雷!
- K8S1.23.5部署(此前1.17版本步骤囊括)及问题记录
- Mongodb3.4升级高版本mongoTemplate.executeCommand报错The cursor option is required
- onnx模型转换opset版本和固定动态输入尺寸
- centos安装指定版本docker
猜你感兴趣
版权申明
本文"SpringCloud-Gateway无法使用Feign服务(2021.X版本)":http://eshow365.cn/6-37030-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!