我正在尝试为两个不同的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
}
您正在对配置类使用@Service
注释。您不需要这样做。根据文档"FooConfiguration
不需要用@Configuration
注释。但是,如果是,请注意将其从包含此配置的任何@ComponentScan
中排除,因为它将成为假装的默认来源。解码器,假装。编码器,假装。合同等,如指定。