commit
16cab0d83c
|
@ -92,27 +92,9 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
|
||||||
// Logger initialization is deferred in case an ordered
|
// Logger initialization is deferred in case an ordered
|
||||||
// LogServletContextInitializer is being used
|
// LogServletContextInitializer is being used
|
||||||
this.logger = LogFactory.getLog(getClass());
|
this.logger = LogFactory.getLog(getClass());
|
||||||
WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
|
WebApplicationContext rootApplicationContext = createRootApplicationContext(servletContext);
|
||||||
if (rootAppContext != null) {
|
if (rootApplicationContext != null) {
|
||||||
servletContext.addListener(new ContextLoaderListener(rootAppContext) {
|
servletContext.addListener(new SpringBootContextLoaderListener(rootApplicationContext, servletContext));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent event) {
|
|
||||||
// no-op because the application context is already initialized
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent event) {
|
|
||||||
try {
|
|
||||||
super.contextDestroyed(event);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
deregisterJdbcDrivers(event.getServletContext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug("No ContextLoaderListener registered, as createRootApplicationContext() did not "
|
this.logger.debug("No ContextLoaderListener registered, as createRootApplicationContext() did not "
|
||||||
|
@ -212,6 +194,10 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ApplicationListener} to trigger
|
||||||
|
* {@link ConfigurableWebEnvironment#initPropertySources(ServletContext, javax.servlet.ServletConfig)}.
|
||||||
|
*/
|
||||||
private static final class WebEnvironmentPropertySourceInitializer
|
private static final class WebEnvironmentPropertySourceInitializer
|
||||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||||
|
|
||||||
|
@ -236,4 +222,34 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ContextLoaderListener} for the initialized context.
|
||||||
|
*/
|
||||||
|
private class SpringBootContextLoaderListener extends ContextLoaderListener {
|
||||||
|
|
||||||
|
private final ServletContext servletContext;
|
||||||
|
|
||||||
|
SpringBootContextLoaderListener(WebApplicationContext applicationContext, ServletContext servletContext) {
|
||||||
|
super(applicationContext);
|
||||||
|
this.servletContext = servletContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent event) {
|
||||||
|
// no-op because the application context is already initialized
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent event) {
|
||||||
|
try {
|
||||||
|
super.contextDestroyed(event);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// Use original context so that the classloader can be accessed
|
||||||
|
deregisterJdbcDrivers(this.servletContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue