Spring Cloud Feign作为HTTP客户端调用远程HTTP服务

如果你的项目使用了SpringCloud微服务技术,那么你就可以使用Feign来作为http客户端来调用远程的http服务。当然,如果你不想使用Feign作为http客户端,也可以使用比如JDK原生的URLConnection、Apache的Http Client、Netty的异步HTTP Client或者Spring的RestTemplate。

那么,为什么我们要使用Feign呢?

首先我们的项目使用了SpringCloud技术,而Feign可以和SpringCloud技术无缝整合。并且,你一旦使用了Feign作为http客户端,调用远程的http接口就会变得像调用本地方法一样简单。

下面就看看Feign是怎么调用远程的http服务的吧。

(1)首先你得引入Feign依赖的jar包:

gradle依赖:

compile "org.springframework.cloud:spring-cloud-netflix-core:1.3.2.RELEASE"

Maven依赖:

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-netflix-core</artifactId>

<version&

相关推荐
咖啡Beans2 天前
SpringCloud网关Gateway功能实现
java·spring cloud
moonless02222 天前
FastAPI框架,这一小篇就能搞懂精髓。
http·fastapi
麦兜*3 天前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
麦兜*3 天前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
青衫客363 天前
Spring异步编程- 浅谈 Reactor 核心操作符
java·spring·响应式编程
熙客3 天前
SpringCloud概述
java·spring cloud·微服务
Cyan_RA93 天前
SpringMVC @RequestMapping的使用演示和细节 详解
java·开发语言·后端·spring·mvc·ssm·springmvc
ftpeak3 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务
网络·http·https·rust·web·web app
wuxuanok3 天前
SpringBoot -原理篇
java·spring boot·spring
若鱼19193 天前
spring-kafka消费异常处理
spring·kafka