代码案例
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)