Feign.Builder from FeignClientsConfiguration overrides SleuthFeignBuilder
See original GitHub issueI am trying to get Sleuth to work correctly with feign clients constructed with Feign.builder. Based on previous posts here and looking at the code, I understand that I can rely on SleuthFeignBuilder
to return a builder that wraps the client in the Trace functionality.
However, I’m not able to inject the correct builder in my Spring application - it seems that the default builder, from org.springframework.cloud.netflix.feign.FeignClientsConfiguration
overrides the Sleuth builder from org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClientAutoConfiguration
since they are both marked as ConditionalOnMissingBean
and the FeignClientsConfiguration
class gets loaded first.
This is the builder in FeignClientsConfiguration
:
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
public Feign.Builder feignBuilder(Retryer retryer) {
return Feign.builder().retryer(retryer);
}
And this is the builder in TraceFeignClientAutoConfiguration
:
@Bean
@ConditionalOnMissingBean
@Scope("prototype")
@ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "false", matchIfMissing = true)
Feign.Builder feignBuilder(BeanFactory beanFactory) {
return SleuthFeignBuilder.builder(beanFactory);
}
How can I get the 2nd one, and not the first?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
@marcingrzejszczak your last comment helped me pinpoint the issue - there was an explicit Import of FeignClientsConfiguration in a different place in the code that caused this conflict, after removing it everything works fine!
The
TraceFeignClientAutoConfiguration
is an autoconfiguration.FeignClientsConfiguration
is not an autoconfiguration. It’s Usef jn theFeignContext
.FeignContext
is setup inFeignAutoConfiguration
. We do have@AutoConfigureBefore(FeignAutoConfiguration.class)
.