spring-cloud / spring-cloud-openfeign

Support for using OpenFeign in Spring Cloud apps
Apache License 2.0
1.2k stars 779 forks source link

Client delegation stopped working #1033

Closed kubav182 closed 2 weeks ago

kubav182 commented 4 months ago

In previous cloud versions 2021.x I could make Client delegation like

@Bean
Client myClient(Client client) {
 // return my client delegating default client
}

Now in version 2023.0.1 I'm getting error Client bean is in creation, so there is circular dependency.

I used it as interceptor around request/response. I understand there is RequestInterceptor and ResponseInterceptor. But RequestInterceptor just decorates RestTemplate and ResponseInterceptor does not contain for example request duration.

Is it bug or is there any other easy way how to get info about request/response + duration? I want to log this info to metric system.

OlgaMaciaszek commented 3 months ago

Hello @kubav182, thanks for creating the issue. It seems that, it's not related in any way to Spring Cloud code, but rather Spring Framework. I can double-check that for you, but in order for us to do it, please provide a minimal, complete, verifiable example that reproduces the issue.

kubav182 commented 3 months ago

@OlgaMaciaszek Hello Olga, I'm quite sure it is caused by FeignAutoConfiguration class. This class uses condition for every client, there is for example OkHttpClient:

@Bean
@ConditionalOnMissingBean(Client.class)
public Client feignClient(okhttp3.OkHttpClient client) {
    return new OkHttpClient(client);
}

As I'm creating Client there is no Client created by autoconfig (ConditionalOnMissingBean). So I'm injecting Client in method where I'm creating it so it is circle. Only solution for me was duplicate code from FeignAutoConfiguration and create client myself, but it depends on what client I'm using if okhttp, apache etc. I'm not sure if it is bug or not, but as I wrote I could do that with cloud version 2021.x.

demo-feign-client-delegation-bug.zip

OlgaMaciaszek commented 2 months ago

Hello @kubav182, we've made some breaking changes in this area in a major release, so it might have been on purpose. However, I will double-check that for you, but please provide your sample as a link to a GH repo, as the sample you've provided doesn't seem to open correctly on a Linux machine.

kubav182 commented 2 months ago

@OlgaMaciaszek Hello I pushed project to public repo https://github.com/kubav182/demo-feign-client-delegation-bug/tree/master

OlgaMaciaszek commented 1 month ago

Thanks @kubav182. Can you specify on which version that used to work? When I've downgraded this to Cloud 2021.0.9 and Boot 2.6.15 it's had the same issue.

In terms of the interceptors, those are the ones you can use, but they are from the external Feign library, so any changes would have to be reported/ added in that repo.

spring-cloud-issues commented 3 weeks ago

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.

spring-cloud-issues commented 2 weeks ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.