OpenFeign简单使用,springcloud

**

OpenFeign

**
springcloud官网地址:
https://spring.io/projects/spring-cloud-openfeign#overview
下面是官网对OpenFeign的一段描述
Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web. Spring Cloud integrates Eureka, Spring Cloud CircuitBreaker, as well as Spring Cloud LoadBalancer to provide a load-balanced http client when using Feign.
在这里插入图片描述
feign本质是一个集成项目的接口调用工具,同时也支持线上注册任务的接口调用方式,比如:nacos,eureka。

依赖

 <!--Spring Cloud OpenFeign Starter -->
        <dependency><groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>

示例:

@FeignClient(value = ServiceAppName.LOGIN_SERVICE_NAME,url = ServiceAppName.LOGIN_SERVICE_URL)
public interface LoginMasterFeign {

@GetMapping("/getUser")
public ReturnObj<Object> userLogin(@RequestParam("username") String username,@RequestParam("password") String password) throws ClassNotFoundException;
}

@FeignClient重要标签,value属性feign接口的名称,url属性对应接口地址:协议://ip:端口/地址。
启动类包扫描:

@EnableFeignClients(basePackages = {
        "com.byun.xxx.feign"
})

basePackages属性feign接口包地址,可以传入多值。
具体详情可以参照官网提供的api文档。
https://docs.spring.io/spring-cloud-openfeign/reference/spring-cloud-openfeign.html
遇到的线上问题:在使用feign,跨module进行http调用时,HttpServletRequest requst不能传输,否则报错。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值