Browse Source

Synchronized onRefresh execution for concurrent ContextRefreshedEvent

Issue: SPR-17442
pull/2011/head
Juergen Hoeller 6 years ago
parent
commit
b1f5f51503
  1. 17
      spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java

17
spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java

@ -209,6 +209,9 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic @@ -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 @@ -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 @@ -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 @@ -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…
Cancel
Save