You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, ConnectionDetailsFactories initializes a SpringFactoriesLoader using its own class loader (ConnectionDetailsFactories.class.getClassLoader()). I propose instead that the SpringFactoriesLoader be initialized with the thread's context class loader (Thread.currentThread().getContextClassLoader()) by default - falling back to the previous behavior if the context class loader is missing.
Motivation
When defining our own ConnectionDetails and ConnectionDetailsFactory in a project that uses spring-boot-devtools, the ConnectionDetails instance created by the factory fails to be autowired. This happens because the class loader used by the factory differs from the one used to wire the bean.
In this example, the application will fail to start with the following error:
Parameter 0 of constructor in com.example.demo.custom.CustomPGClient required a bean of type 'com.example.demo.custom.CustomPGConnectionDetails' that could not be found.
Disclaimer
My understanding of the inner workings of Spring is limited, so there might be a good reason this isn't already done.
If that's the case, please let me know so we can explore alternatives or consider opening a broader issue to address the underlying problem.
The text was updated successfully, but these errors were encountered:
Proposal
At the moment,
ConnectionDetailsFactories
initializes aSpringFactoriesLoader
using its own class loader (ConnectionDetailsFactories.class.getClassLoader()
). I propose instead that theSpringFactoriesLoader
be initialized with the thread's context class loader (Thread.currentThread().getContextClassLoader()
) by default - falling back to the previous behavior if the context class loader is missing.Motivation
When defining our own
ConnectionDetails
andConnectionDetailsFactory
in a project that usesspring-boot-devtools
, theConnectionDetails
instance created by the factory fails to be autowired. This happens because the class loader used by the factory differs from the one used to wire the bean.Example
src/main/java/com/example/custom/demo/CustomPGConnectionDetails.java
src/main/java/com/example/custom/demo/CustomPGDockerComposeConnectionDetailsFactory.java
src/main/java/com/example/custom/demo/CustomPGClient.java
src/main/resources/META-INF/spring.factories
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=com.example.demo.custom.CustomPGDockerComposeConnectionDetailsFactory
In this example, the application will fail to start with the following error:
Disclaimer
My understanding of the inner workings of Spring is limited, so there might be a good reason this isn't already done.
If that's the case, please let me know so we can explore alternatives or consider opening a broader issue to address the underlying problem.
The text was updated successfully, but these errors were encountered: