@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 201 7 the original author or authors .
* Copyright 2012 - 201 8 the original author or authors .
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -17,10 +17,12 @@
package org.springframework.boot.web.embedded.tomcat ;
import org.apache.catalina.Container ;
import org.apache.catalina.LifecycleException ;
import org.apache.catalina.Manager ;
import org.apache.catalina.core.StandardContext ;
import org.apache.catalina.session.ManagerBase ;
import org.springframework.util.Assert ;
import org.springframework.util.ClassUtils ;
import org.springframework.util.ReflectionUtils ;
@ -59,7 +61,7 @@ class TomcatEmbeddedContext extends StandardContext {
super . setManager ( manager ) ;
}
public void deferredLoadOnStartup ( ) {
public void deferredLoadOnStartup ( ) throws LifecycleException {
// Some older Servlet frameworks (e.g. Struts, BIRT) use the Thread context class
// loader to create servlet instances in this phase. If they do that and then try
// to initialize them later the class loader may have changed, so wrap the call to
@ -70,15 +72,20 @@ class TomcatEmbeddedContext extends StandardContext {
if ( classLoader ! = null ) {
existingLoader = ClassUtils . overrideThreadContextClassLoader ( classLoader ) ;
}
if ( this . overrideLoadOnStart ) {
// Earlier versions of Tomcat used a version that returned void. If that
// version is used our overridden loadOnStart method won't have been called
// and the original will have already run.
super . loadOnStartup ( findChildren ( ) ) ;
try {
if ( this . overrideLoadOnStart ) {
// Earlier versions of Tomcat used a version that returned void. If that
// version is used our overridden loadOnStart method won't have been
// called and the original will have already run.
boolean started = super . loadOnStartup ( findChildren ( ) ) ;
Assert . state ( started ,
"Unable to start embedded tomcat context " + getName ( ) ) ;
}
}
if ( existingLoader ! = null ) {
ClassUtils . overrideThreadContextClassLoader ( existingLoader ) ;
finally {
if ( existingLoader ! = null ) {
ClassUtils . overrideThreadContextClassLoader ( existingLoader ) ;
}
}
}