@FeignClient(configuration=xyz.class) not working as expected
I've a specific error decoder, which should only be used for one client:
@FeignClient(name = "a",, configuration = [AConfig::class])
interface ClientA {...}
@FeignClient(name = "b")
interface ClientB {...}
class AConfig {
@Bean
fun aErrorDecoder(): AErrorDecoder = AErrorDecoder()
inner class AErrorDecoder : ErrorDecoder {
private val defaultErrorDecoder = ErrorDecoder.Default()
override fun decode(methodKey: String?, response: Response?): Exception {
if (HttpStatus.NOT_FOUND.value() == response?.status()) {
return SomeException()
}
return defaultErrorDecoder.decode(methodKey, response)
}
}
}
@SpringBootApplication
@EnableFeignClients
class Application
Problem: Requests for ClientB are also handled by the custom ErrorDecoder, which should not be the case.
Version: Spring Cloud Finchley.SR1
Comment From: ryanjbaxter
Is AConfig annotated with @Configuration?
From our 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. This can be avoided by putting it in a separate, non-overlapping package from any @ComponentScan or @SpringBootApplication, or it can be explicitly excluded in @ComponentScan.
Comment From: rowi1de
Is
AConfigannotated with@Configuration?
No it's not, that's the reason why I'm surprised about this behaviour 🤔
If I add the following to application.yml, the AErrorDecoder isn't used for any client. Because properties wins(?). ```yaml feign: client: config: default: errorDecoder: feign.codec.ErrorDecoder.Default
However the following works:
```yaml
feign:
client:
config:
bClient:
errorDecoder: feign.codec.ErrorDecoder.Default
Comment From: ryanjbaxter
Can you provide a sample so we can take a look?
Comment From: rowi1de
Not today, but I hope to be able soon
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: rowi1de
Created this example: https://github.com/rowi1de/spring-cloud-openfeign-issue-72 But in this setup it works. I'm trying to find the difference to the setup that is not working
Comment From: ryanjbaxter
I am going to close this for now. Once you have a sample that reproduces the issue, please comment and we can reopen and take a look.
Comment From: vprasanna80
I am facing the same issue as well. When i create a custom error decoder and apply it for a specific feign client, it's applying it for all the feign clients. For example,
feign: client: config: aClient: readTimeout: 15000 bClient: errorDecoder: feign.codec.ErrorDecoder.Default cClient: readTimeout: 15000
In this example, the custom error decoder is applied only for bClient whereas it gets executed for all the clients namely aClient, bClient and cClient.