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
Lazy dependency proxy does not populate bean dependencies #25562
Comments
Spring Boot 2.3 uses the same Spring Framework generation as Spring Boot 2.2. If you've debugged this, it would be nice to share the two Spring Framework versions that you've used. |
Yes, it seems to be Spring 5.2.8.RELEASE in both cases. Should this be routed to Boot then? |
Thank you. I've reproduced the problem and it does not occur with Spring Boot |
It's interesting to see that the bean dependencies aren't available in the core |
I think this is a Framework bug. The change in behaviour is due to the JPA repositories being lazy by default in Spring Boot 2.3. The repository dependencies are detected again if you set Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(
descriptor, requestingBeanName);
if (result == null) {
result = doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
}
return result; In the lazy case, |
Very nice detective work @wilkinsona! @BoykoAlex you can workaround the problem in the meantime adding the following to
|
@jhoeller I've tentatively assigned |
This is more or less by design: Lazy proxy resolution doesn't know the actual targets upfront, and when it's eventually triggered, we cannot populate the original |
I got an implementation that's pretty straightforward, can easily make 5.2.9... |
And since this is somewhat unintuitive indeed when switching to a lazy dependency proxy, I'll consider it a bug fix to backport... |
Did this change make it into the 5.2.10 release? I am trying a pet clinic at Spring Boot 2.3.5 with Framework at 5.2.10 and the bean dependencies for the OwnerController (in our example above) are still empty. Will dive deeper tomorrow, but just wondering whether this fix made it into that version or not. |
@martinlippert see the milestone above - it made it into 5.2.9 and got backported all the way down to 4.3.29. Not sure why it's not working for PetClinic with Boot 2.3.5 still. The fix here was only really addressing the core |
I'm still seeing the same JSON for the |
Please note that dependencies behind a lazy proxy are only going to be registered once the proxy is actually being initialized, that is, once a method invocation on the proxy led to the resolution of the target instance. That's the part that the fix addressed here. |
@jhoeller Thanks for the last comment that clarified it really :-) Seems to all work as expected now. As soon as I add a new pet owner i see the clinic repo dependency. Think this is great :-) |
Start off with the latest spring-petclinic project based on Boot 2.3.x
Launch the app and see the JSON response for
/actuator/beans
Search for
OwnerController
bean. This bean should depend onOwnerRepository
andPetRepository
. The JSON for the bean however is this:If spring-petclinic is switched to Boot 2.2.x then the dependencies are detected correctly:
Something is off in the framework as actuator simply calls
org.springframework.beans.factory.config.ConfigurableBeanFactory.getDependenciesForBean(String)
Try this in the
org.springframework.samples.petclinic.PetClinicApplication
for the main method:You'd see that there are no dependencies returned in the Boot 2.3.x case.
The text was updated successfully, but these errors were encountered: