Synchronized onRefresh execution for concurrent ContextRefreshedEvent
Issue: SPR-17442
This commit is contained in:
parent
2ce03f34d9
commit
b1f5f51503
|
@ -209,6 +209,9 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
/** Should we dispatch an HTTP TRACE request to {@link #doService}?. */
|
||||
private boolean dispatchTraceRequest = false;
|
||||
|
||||
/** Whether to log potentially sensitive info (request params at DEBUG + headers at TRACE). */
|
||||
private boolean enableLoggingRequestDetails = false;
|
||||
|
||||
/** WebApplicationContext for this servlet. */
|
||||
@Nullable
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
@ -217,10 +220,10 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
private boolean webApplicationContextInjected = false;
|
||||
|
||||
/** Flag used to detect whether onRefresh has already been called. */
|
||||
private boolean refreshEventReceived = false;
|
||||
private volatile boolean refreshEventReceived = false;
|
||||
|
||||
/** Whether to log potentially sensitive info (request params at DEBUG + headers at TRACE). */
|
||||
private boolean enableLoggingRequestDetails = false;
|
||||
/** Monitor for synchronized onRefresh execution. */
|
||||
private final Object onRefreshMonitor = new Object();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -591,7 +594,9 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
// Either the context is not a ConfigurableApplicationContext with refresh
|
||||
// support or the context injected at construction time had already been
|
||||
// refreshed -> trigger initial onRefresh manually here.
|
||||
onRefresh(wac);
|
||||
synchronized (this.onRefreshMonitor) {
|
||||
onRefresh(wac);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.publishContext) {
|
||||
|
@ -832,7 +837,9 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||
*/
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
this.refreshEventReceived = true;
|
||||
onRefresh(event.getApplicationContext());
|
||||
synchronized (this.onRefreshMonitor) {
|
||||
onRefresh(event.getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue