|
|
@ -16,12 +16,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.context.embedded.tomcat;
|
|
|
|
package org.springframework.boot.context.embedded.tomcat;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.Lifecycle;
|
|
|
|
import org.apache.catalina.Lifecycle;
|
|
|
|
import org.apache.catalina.LifecycleEvent;
|
|
|
|
import org.apache.catalina.LifecycleEvent;
|
|
|
|
import org.apache.catalina.LifecycleListener;
|
|
|
|
import org.apache.catalina.LifecycleListener;
|
|
|
|
import org.apache.catalina.core.StandardContext;
|
|
|
|
import org.apache.catalina.core.StandardContext;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.springframework.boot.context.embedded.ServletContextInitializer;
|
|
|
|
import org.springframework.boot.context.embedded.ServletContextInitializer;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
|
@ -29,10 +29,15 @@ import org.springframework.util.Assert;
|
|
|
|
* Tomcat {@link LifecycleListener} that calls {@link ServletContextInitializer}s.
|
|
|
|
* Tomcat {@link LifecycleListener} that calls {@link ServletContextInitializer}s.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
|
|
|
* @author Dave Syer
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ServletContextInitializerLifecycleListener implements LifecycleListener {
|
|
|
|
public class ServletContextInitializerLifecycleListener implements LifecycleListener {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Log logger = LogFactory
|
|
|
|
|
|
|
|
.getLog(ServletContextInitializerLifecycleListener.class);
|
|
|
|
|
|
|
|
|
|
|
|
private final ServletContextInitializer[] initializers;
|
|
|
|
private final ServletContextInitializer[] initializers;
|
|
|
|
|
|
|
|
private Exception startUpException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a new {@link ServletContextInitializerLifecycleListener} instance with the
|
|
|
|
* Create a new {@link ServletContextInitializerLifecycleListener} instance with the
|
|
|
@ -44,6 +49,10 @@ public class ServletContextInitializerLifecycleListener implements LifecycleList
|
|
|
|
this.initializers = initializers;
|
|
|
|
this.initializers = initializers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Exception getStartUpException() {
|
|
|
|
|
|
|
|
return this.startUpException;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void lifecycleEvent(LifecycleEvent event) {
|
|
|
|
public void lifecycleEvent(LifecycleEvent event) {
|
|
|
|
if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) {
|
|
|
|
if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) {
|
|
|
@ -53,8 +62,13 @@ public class ServletContextInitializerLifecycleListener implements LifecycleList
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
initializer.onStartup(standardContext.getServletContext());
|
|
|
|
initializer.onStartup(standardContext.getServletContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ServletException ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
throw new IllegalStateException(ex);
|
|
|
|
this.startUpException = ex;
|
|
|
|
|
|
|
|
// Prevent Tomcat from logging and re-throwing when we know we can
|
|
|
|
|
|
|
|
// deal with it in the main thread, but log for information here.
|
|
|
|
|
|
|
|
logger.error("Error starting Tomcat context: "
|
|
|
|
|
|
|
|
+ ex.getClass().getName());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|