一个Spring应用程序中具有不同errorDecoders的几个Feign Client

时间:2019-10-12 18:36:25

标签: spring-boot feign

我正在尝试为两个不同的Feign客户端实现两个不同的errorDecoder。 我的应用程序无法启动异常

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 个答案:

没有答案