|
|
|
@ -18,7 +18,6 @@ package org.springframework.boot.context.embedded.jetty;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|
|
|
|
import org.eclipse.jetty.webapp.AbstractConfiguration;
|
|
|
|
|
import org.eclipse.jetty.webapp.Configuration;
|
|
|
|
|
import org.eclipse.jetty.webapp.WebAppContext;
|
|
|
|
@ -49,54 +48,35 @@ public class ServletContextInitializerConfiguration extends AbstractConfiguratio
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configure(WebAppContext context) throws Exception {
|
|
|
|
|
context.addBean(new Initializer(context), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer
|
|
|
|
|
* ServletContextInitializers}.
|
|
|
|
|
*/
|
|
|
|
|
private class Initializer extends AbstractLifeCycle {
|
|
|
|
|
|
|
|
|
|
private final WebAppContext context;
|
|
|
|
|
|
|
|
|
|
Initializer(WebAppContext context) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void doStart() throws Exception {
|
|
|
|
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
Thread.currentThread().setContextClassLoader(this.context.getClassLoader());
|
|
|
|
|
Thread.currentThread().setContextClassLoader(context.getClassLoader());
|
|
|
|
|
try {
|
|
|
|
|
callInitializers();
|
|
|
|
|
callInitializers(context);
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
Thread.currentThread().setContextClassLoader(classLoader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void callInitializers() throws ServletException {
|
|
|
|
|
private void callInitializers(WebAppContext context) throws ServletException {
|
|
|
|
|
try {
|
|
|
|
|
setExtendedListenerTypes(true);
|
|
|
|
|
for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) {
|
|
|
|
|
initializer.onStartup(this.context.getServletContext());
|
|
|
|
|
setExtendedListenerTypes(context, true);
|
|
|
|
|
for (ServletContextInitializer initializer : this.initializers) {
|
|
|
|
|
initializer.onStartup(context.getServletContext());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
setExtendedListenerTypes(false);
|
|
|
|
|
setExtendedListenerTypes(context, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setExtendedListenerTypes(boolean extended) {
|
|
|
|
|
private void setExtendedListenerTypes(WebAppContext context, boolean extended) {
|
|
|
|
|
try {
|
|
|
|
|
this.context.getServletContext().setExtendedListenerTypes(extended);
|
|
|
|
|
context.getServletContext().setExtendedListenerTypes(extended);
|
|
|
|
|
}
|
|
|
|
|
catch (NoSuchMethodError ex) {
|
|
|
|
|
// Not available on Jetty 8
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|