-
Notifications
You must be signed in to change notification settings - Fork 705
Refreshing from a background thread can skip autoconfiguration and miss config changes #840
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
Comments
I'm not sure there's anything we can do for auto-configuration. It is |
According to the JavaDoc you have to set a system property pointing to a custom
|
Related: spring-projects/spring-boot#15737 |
Not sure there's anything to do. |
I’ve been able to workaround this so I’m fine closing |
Describe the bug
Spring Boot 2.3.4.RELEASE w/ Spring Cloud Hoxton.SR8 (also tested 2.2.x w/ Hoxton.SR4) on Java 11
This may not be a bug, but it's behavior that was unexpected to me so I thought I'd report it here at least for posterity.
Normally, triggering a refresh (e.g. by calling
RefreshEndpoint
) causes autoconfiguration to run again, picking up config changes (among other things). However, when triggered from a background thread (e.g. viaApplicationEventPublisher.publishEvent(new RefreshEvent(this, event, desc))
) it's possible that autoconfiguration classes, includingPropertySourceBootstrapConfiguration
, are not called so config changes are not picked up. Debugging through the code, it looks like the background thread's ContextClassLoader is used fororg.springframework.core.io.support.SpringFactoriesLoader
in the new (refreshed) bootstrap context and it might not find anyspring.factories
files, as is the case withjava.util.concurrent.ForkJoinPool.commonPool()
. Since ContextClassLoaders are inherited, I doubt this comes up often outside of the ForkJoin common pool.Examples
When started via
java -jar
aorg.springframework.boot.loader.LaunchedURLClassLoader
is used bySpringFactoriesLoader
on the initial bootstrap context and autoconfiguration works. When refreshing usingRefreshEndpoint
, aorg.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader
is used bySpringFactoriesLoader
and autoconfiguration works. When refreshing from a ForkJoin common pool thread,jdk.internal.loader.ClassLoaders.AppClassLoader
(the JVM default I think) is used bySpringFactoriesLoader
and nospring.factories
files are found thus autoconfiguration is skipped.Sample
I can provide a sample project if that will help, just let me know.
The text was updated successfully, but these errors were encountered: