-
Notifications
You must be signed in to change notification settings - Fork 41.1k
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
ConnectionDetailsFactories should use the context class loader to load factories #45014
Conversation
Add flag to determine whether to use context class loader or ConnectionDetailsFactory class loader on ConnectionDetailsFactories. Signed-off-by: lengors <24527258+lengors@users.noreply.github.com>
ConnectionDetailsFactories
for context class loaderUpdate `ConnectionDetailsFactories` so that the context classloader can be used to load factories. See gh-45014 Signed-off-by: lengors <24527258+lengors@users.noreply.github.com>
Refine the submitted pull-request to remove the configuration property with the assumption that the context classloader will work for all cases. See gh-45014
Thanks very much for the PR @lengors. I think it's possible to argue that this is a bug, however, it feels a little risky to fix in a patch release so I'm keeping the target to 3.5. I've refined your contribution a little to remove the property support and always use the context classloader. I think this should be fine, but if we find it introduces problems we can consider reintroducing the property. If you can, please give the 3.5.x SNAPSHOT a go when https://github.com/spring-projects/spring-boot/actions/runs/14342588861 has finished to check that it solves your problem. Thanks! |
@philwebb Thanks for reviewing. Correct me if I'm wrong but as it stands, on This would match the test I did where the custom That said, I think being able to specify the classloader to instantiate |
I think it should be OK, the factories code ends up being used here which call this That being said, this stuff is quite hard to test so please let me know if you find things still aren't working as expected. |
I've create a repository to illustrate the issue: https://github.com/lengors/spring-connection-details-factory-issue But, I also take a look in the meantime, and I think the issue is here where, if the classloader passed to So, I think it needs to be explicitly passed to the |
Oh no, I totally missed that code and it behaves differently than I expected. I think it might be done that way for back-compatibility reasons. I think that classloader is used there to load the factories files, and the other code is used to create the class. I'll run the sample you've provided and check. |
It looks like we have a bug in Spring Framework causing cache pollution. I've submitted spring-projects/spring-framework#34732. I've also put a work around in commit 4af0ee2. With that in place, the sample application works. Thanks for your persistence getting this fixed! |
I gave it a test on both the sample application I provided and on an actual application I'm developing and both seemingly work. I'll keep using the Thank you very much for the work you've put into this! |
Add flag to determine whether to use context class loader or
ConnectionDetailsFactory
class loader inConnectionDetailsFactories
.Implements #45010.
I introduced a new constructor in
ConnectionDetailsFactories
that allows selecting between the thread’s context class loader and theConnectionDetailsFactory
class's class loader. retains the previous behavior to ensure backward compatibility.Additionally, I extended
DockerComposeProperties
with a new flag (defaulting tofalse
) that reflects this setting. TheDockerComposeServiceConnectionsApplicationListener
now uses this flag when creating theConnectionDetailsFactories
.I chose this approach to maintain the old behavior by default. If there's consensus that always using the thread’s context class loader is sufficient, I’m happy to simplify the implementation accordingly.