Spring Cloud - Feign RequestInterceptor 拦截器

代码案例

package com.luxsun.platform.lux.kernel.common.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FeignConfig implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        
    }
}
  • 实现接口代码
package com.luxsun.platform.lux.kernel.common.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class FeignHandler {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            
        };
    }
}
  • 注解方式代码

配置方案

1、yml 配置:feign.client.config.default.requestInterceptors (会覆盖 Java 配置方式)

feign:
  client:
    config:
      default:
        connectTimeout: 60000
        readTimeout: 60000
        requestInterceptors:
          - com.luxsun.platform.lux.kernel.common.config.FeignConfig

2、Application.java 全局配置:@EnableFeignClients 属性 defaultConfiguration = XXX.class

@EnableFeignClients(defaultConfiguration = FeignConfig.class)

3、注解配置:@Configuration + @Bean

  • 如上注解方式代码

4、@FeignClient 配置:属性 configuration = XXX.class

@FeignClient(configuration = FeignHandler.class)

注意:FeignConfig 一定是在消费者使用,而不是放在提供者!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆氪和他的那些代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值