在以编程方式创建的 feign 客户端上获取 Spring 默认 Feign 选项
我正在尝试获取默认的 feign 选项/配置,以在我使用 Feign.Builder 以编程方式创建的 feign 客户端中使用它:
这是我想要获取的配置(application.yaml):
feign:
client:
config:
default:
connect-timeout: 5000
read-timeout: 5000
我试图做的是添加 @EnableFeignClients 并尝试获取 FactoryBean
我还尝试在 StackOverflow 和其他网站中搜索,看看是否有其他人尝试过我想做的事情,但我无法找到任何信息,因此我创建了这个问题。
public MyClientFactory(Client client,
ObjectMapper objectMapper,
FactoryBean<Request.Options> optionsFactory,
ErrorDecoder errorDecoder) throws Exception {
this.builder = Feign.builder()
.client(client)
.decoder(new JacksonDecoder(objectMapper))
.encoder(new JacksonEncoder(objectMapper))
.options(optionsFactory.getObject())
.errorDecoder(errorDecoder);
}
有人可以让我知道如何获得默认的 spring feign 配置吗?也许我的方法不正确?
谢谢!
I am trying to get the default feign options/config to use it in feign clients that I create programatically using Feign.Builder:
This is the config (application.yaml) that I want to get:
feign:
client:
config:
default:
connect-timeout: 5000
read-timeout: 5000
What I tried to do is to do is to add @EnableFeignClients and try to get the FactoryBean<Request.Options> or it's implementation OptionsFactoryBean but I don't see it being injected by Spring anywhere.
I've also tried searching in StackOverflow and other websites to see if there are other people that have tried what I am trying to do, but I wasn't able to find any information hence why I am creating this question.
public MyClientFactory(Client client,
ObjectMapper objectMapper,
FactoryBean<Request.Options> optionsFactory,
ErrorDecoder errorDecoder) throws Exception {
this.builder = Feign.builder()
.client(client)
.decoder(new JacksonDecoder(objectMapper))
.encoder(new JacksonEncoder(objectMapper))
.options(optionsFactory.getObject())
.errorDecoder(errorDecoder);
}
Can someone please let me know how I can get the default spring feign configs? Maybe my approach is incorrect?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还没有尝试过,但我假设你需要来自 FeignClientProperties 类。
Haven't tried it but I assume you'll need a bean from the FeignClientProperties class.
我最终根据 @Arnold Galovics 建议创建了一个基于 FeignClientProperties 的 Request.Options @Bean 。
然后我将这个 bean 注入到我的 Feign Client Factory 中:
I ended up creating a Request.Options @Bean based on FeignClientProperties as @Arnold Galovics suggested.
And then I injected this bean in my Feign Client Factory: