Several Feign Clients with different errorDecoders in one Spring application

Viewed 394

I'm trying to implement two different errorDecoders for two different Feign clients. My application fails to start exception

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.client.ClientFirst': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'feign.codec.ErrorDecoder' available: expected single matching bean but found 2: errorDecoder,ClientFirstErrorDecoder

// First configuration

@RequiredArgsConstructor
@Service
@Slf4j
public class ClientFirstConfiguration {

    @Bean(name = "ClientFirstErrorDecoder")
    public ErrorDecoder errorDecoder() {
          // omitted for brevity
        };
    }
}

// Second configuration

@RequiredArgsConstructor
@Service
@Slf4j
public class ClientSecondConfiguration {

    public ErrorDecoder errorDecoder() {
          // omitted for brevity
        };
    }
}

// First client

@FeignClient(
        name = "feign.client.config.first",
        url = "${first.url}",
        configuration = {
                FeignDefaultConfiguration.class,
                ClientFirstConfiguration.class
        }
)
@Headers({"Content-Type: application/json"})
public interface ClientFirst {
// omitted for brevity
}

// Second client

@FeignClient(
        name = "feign.client.config.second",
        url = "${second.url}",
        configuration = {
                FeignDefaultConfiguration.class,
                ClientSecondConfiguration.class
        }
)
@Headers({"Content-Type: application/json"})
public interface ClientSecond {
// omitted for brevity
}
0 Answers
Related