spring boot feign client decode404 property remains persistent between clients once set to true

879 views Asked by At

Given an application that has several Feign clients, all of them having their configuration detailed in the @FeignClient annotation, as they are instantiated, when one of these clients presents the flag decode404 to true, the rest of the subsequent clients that are instantiated present this flag to true regardless of the configuration they have.

The application is configured to instiate the clients using Hystrix as the resilience provider, for so, the Feign.Builder bean is defined use the Hystrix Builder

@Bean
  Feign.Builder feignClient() {
    return HystrixFeign.builder();
  }

I do have for a given service, several Feign clients declared so I can interact with several other services. Some have configuration classes, some are plain default configured and one of them has the inlined decode404 annotation in int

@FeignClient(
    value = "integration-service",
    configuration = IntegrationHttpClientConfiguration.class)
public interface IntegrationHttpClient {
@FeignClient(value = "brand-admin-service")
public interface BrandAdminHttpClient {
@FeignClient(value = "loyalty-points-service", decode404 = true)
public interface LoyaltyPointsClient {

At boot time this clients are instiated by Spring as soon as they are required by the constructor of the Services that requires them. (They are not explicitly declared in any configuration class)

@Slf4j
@Validated
@RequiredArgsConstructor
@Service
public class ContactUsService {

  private final BrandAdminHttpClient brandAdminHttpClient;

  private final LoyaltyPointsClient loyaltyPointsClient;

  private final IntegrationHttpClient integrationHttpClient;

Following this approach we founded that any client declared and hence instiated after the one marked with decode404 still got that flag to true. In the code provided integrationHttpClient despite having that value to false as it is the default value, will present it to true, as de Fegin.Builder used by the spring context gets polluted by the previous one and has no way to reset the value back (nor the Spring Feign Factory attempts to do so).

Is this known issue?

Tested over Spring Cloud Open Feign 3.1.3 (OpenFeign 11.8) and 2.2.1.RELEASE (OpenFeign 10.4). The updated versions of Feign had renamed the decode404 to dismiss404 but the internal factory logic stays the same.

We have already found a few ways to workaround this issue but it doesn't seems right to do so. (Both by Scoping and defining a priority config)


Update

As asked for

IntegrationHttpClientConfiguration.class

This just defines a custome error decode for the client to use

public class IntegrationHttpClientConfiguration {

  @Bean
  public ErrorDecoder errorDecoder(ObjectMapper objectMapper) {
    return new IntegrationHttpClientErrorDecoder(objectMapper);
  }
}

Update 2

The following repo has a working example where the problem is reproduced.

0

There are 0 answers