Commit b4aaeaac authored by Dave Syer's avatar Dave Syer

Set Thread context class loader while Tomcat starts up

Fixes gh-1085
parent c0efd3a2
...@@ -18,6 +18,7 @@ package org.springframework.boot.context.embedded.tomcat; ...@@ -18,6 +18,7 @@ package org.springframework.boot.context.embedded.tomcat;
import org.apache.catalina.Container; import org.apache.catalina.Container;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
import org.springframework.util.ClassUtils;
/** /**
* Tomcat {@link StandardContext} used by {@link TomcatEmbeddedServletContainer} to * Tomcat {@link StandardContext} used by {@link TomcatEmbeddedServletContainer} to
...@@ -32,7 +33,20 @@ class TomcatEmbeddedContext extends StandardContext { ...@@ -32,7 +33,20 @@ class TomcatEmbeddedContext extends StandardContext {
} }
public void deferredLoadOnStartup() { public void deferredLoadOnStartup() {
// 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
// loadOnStartup in what we think its going to be the main webapp classloader at
// runtime.
ClassLoader classLoader = getLoader().getClassLoader();
ClassLoader existingLoader = null;
if (classLoader != null) {
existingLoader = ClassUtils.overrideThreadContextClassLoader(classLoader);
}
super.loadOnStartup(findChildren()); super.loadOnStartup(findChildren());
if (existingLoader != null) {
ClassUtils.overrideThreadContextClassLoader(existingLoader);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment