@ -54,9 +54,11 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
@@ -54,9 +54,11 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext ;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory ;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext ;
import org.springframework.boot.context.event.ApplicationFailedEvent ;
import org.springframework.boot.web.filter.ApplicationContextHeaderFilter ;
import org.springframework.context.ApplicationContext ;
import org.springframework.context.ApplicationContextAware ;
import org.springframework.context.ApplicationEvent ;
import org.springframework.context.ApplicationListener ;
import org.springframework.context.ConfigurableApplicationContext ;
import org.springframework.context.annotation.Bean ;
@ -172,7 +174,7 @@ public class EndpointWebMvcAutoConfiguration
@@ -172,7 +174,7 @@ public class EndpointWebMvcAutoConfiguration
EmbeddedServletContainerAutoConfiguration . class ,
DispatcherServletAutoConfiguration . class ) ;
registerEmbeddedServletContainerFactory ( childContext ) ;
CloseEventPropagation Listener . addIfPossible ( this . applicationContext ,
CloseManagementContext Listener . addIfPossible ( this . applicationContext ,
childContext ) ;
childContext . refresh ( ) ;
managementContextResolver ( ) . setApplicationContext ( childContext ) ;
@ -235,25 +237,42 @@ public class EndpointWebMvcAutoConfiguration
@@ -235,25 +237,42 @@ public class EndpointWebMvcAutoConfiguration
}
/ * *
* { @link ApplicationListener } to propagate the { @link ContextClosedEvent } from a
* parent to a child .
* { @link ApplicationListener } to propagate the { @link ContextClosedEvent } and
* { @link ApplicationFailedEvent } from a parent to a child .
* /
private static class CloseEventPropagation Listener
implements ApplicationListener < ContextClosed Event> {
private static class CloseManagementContext Listener
implements ApplicationListener < Application Event> {
private final ApplicationContext parentContext ;
private final ConfigurableApplicationContext childContext ;
CloseEventPropagation Listener ( ApplicationContext parentContext ,
CloseManagementContext Listener ( ApplicationContext parentContext ,
ConfigurableApplicationContext childContext ) {
this . parentContext = parentContext ;
this . childContext = childContext ;
}
@Override
public void onApplicationEvent ( ContextClosedEvent event ) {
if ( event . getApplicationContext ( ) = = this . parentContext ) {
public void onApplicationEvent ( ApplicationEvent event ) {
if ( event instanceof ContextClosedEvent ) {
onContextClosedEvent ( ( ContextClosedEvent ) event ) ;
}
if ( event instanceof ApplicationFailedEvent ) {
onApplicationFailedEvent ( ( ApplicationFailedEvent ) event ) ;
}
} ;
private void onContextClosedEvent ( ContextClosedEvent event ) {
propagateCloseIfNecessary ( event . getApplicationContext ( ) ) ;
}
private void onApplicationFailedEvent ( ApplicationFailedEvent event ) {
propagateCloseIfNecessary ( event . getApplicationContext ( ) ) ;
}
private void propagateCloseIfNecessary ( ApplicationContext applicationContext ) {
if ( applicationContext = = this . parentContext ) {
this . childContext . close ( ) ;
}
}
@ -268,7 +287,7 @@ public class EndpointWebMvcAutoConfiguration
@@ -268,7 +287,7 @@ public class EndpointWebMvcAutoConfiguration
private static void add ( ConfigurableApplicationContext parentContext ,
ConfigurableApplicationContext childContext ) {
parentContext . addApplicationListener (
new CloseEventPropagation Listener ( parentContext , childContext ) ) ;
new CloseManagementContext Listener ( parentContext , childContext ) ) ;
}
}