3

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
}
Capacytron
  • 3,425
  • 6
  • 47
  • 80

1 Answers1

0

You are using @Service annotation for your configuration classes. You don't need to do this. According documentation "FooConfiguration does not need to be annotated with @Configuration. However, if it is, then take care to exclude it from any @ComponentScan that would otherwise include this configuration as it will become the default source for feign.Decoder, feign.Encoder, feign.Contract, etc., when specified."

Alex
  • 1
  • 2