-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@FeignClient and manual Feign Client #1852
Comments
Maybe it is an order issue? The auto configuration may be running before we create the Feign clients. |
Possible, yes - but still, I have two feign clients (one created automatically, one manually) for the same endpoint. And I can autowire the endpoint interface anywhere throughout my application and it works - so how come there's no clash? Like I said - I'm glad it works, just wanting to understand. |
The @FeignClient bean is created first. Even though the auto configuration bean method is annotated as
it returns the automatically created @FeignClient, to be more exact a Proxy with a |
If you created the Feign client manually and return it as a bean in the application using the lib does it work as you expect? |
@ryanjbaxter if I create the Feign client manually, everything behaves as expected - the conditional in the library recognizes its existence and so does not create a second one. Can you point me to the place in the Feign implementation where the annotated beans are created? |
The bean definitions are created in |
Well, I love a good puzzle, but I'm close to just letting this one rest... since it works, somehow. The
even though inside the method with the conditional, I can retrieve the very Feign client automatically created. When creating the client manually through the Builder, Spring will discover it and not jump into the conditional method:
My best guess right now is that this is more an issue within the Spring framework itself (bean factory), not so much the Spring Cloud Netflix Feign implementation. If I have some time in the future, I might investigate a little further - use newer versions, try out comparable behaviour of other |
@thorstenfrank can you try specifying an order on your auto configuration using |
Not sure the order will help, since the registrar is |
No love, but it was worth a try - both lowest and highest precedence have no effect, the results are identical. Also, not really sure that's what I would want, since I do want the Feign clients to be created first (if they exist), and to only have my auto configuration run if the host application does not already provide a valid Feign client. As mentioned before, the puzzling thing to me isn't the registrar or the ordering, but the fact that the bean factory doesn't recognize the |
I didn't think it would. We'd need to restructure |
Just out of curiosity, I tried to place the I tried this because I had a similar situation at work today where the conditional only worked this way, not at the method level. But in that specific scenario, the bean the conditional was based on was also created by an auto configuration, not a registrar. |
Again, I think the problem is that the registrar is NOT created by auto configuration |
I agree, I just wanted to double-check. As mentioned, I don't understand the Spring loading mechanisms well enough to judge this effect... |
Is there a plan to have the Feign registrar trigger an auto configuration? |
Not currently |
Closing due to age of the question. If you would like us to look at this issue, please comment and we will look at re-opening the issue. |
Just a follow-up/work-around/solution: The only solution around this specific issue is to only use one of the two approaches throughout: annotations (where the We've decided to go with all annotations and marking the library clients as non-primary. |
Here's my scenario:
I have a library used by various Spring Boot applications. The library has a dependency to some ServiceProvider REST API. I can't simply create a @FeignClient inside my lib, because if the App that's using it also declares one to the same interface, it doesn't start up because of a
NoUniqueBeanDefinitionException
.I help myself around this by using auto configuration in the lib like so:
}
Which works, at the end of the day. BUT - I can see in the logs that the manually built client is always created, even if the host application supplies something like
I can use the
ServiceProvider
from both inside the app and the library, I just don't know how this works... shouldn't the library be re-using the@FeignClient
from the host?Full example available here: https://github.com/thorstenfrank/multi-feign-clients
The text was updated successfully, but these errors were encountered: