Reflection hack for Tomcat 8 API change

Fixes gh-1148
This commit is contained in:
Dave Syer 2014-06-25 11:35:44 +01:00
parent fda24b8499
commit 5d317f2dc7
2 changed files with 15 additions and 1 deletions

View File

@ -16,9 +16,12 @@
package org.springframework.boot.context.embedded.tomcat; package org.springframework.boot.context.embedded.tomcat;
import java.lang.reflect.Method;
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; import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
/** /**
* Tomcat {@link StandardContext} used by {@link TomcatEmbeddedServletContainer} to * Tomcat {@link StandardContext} used by {@link TomcatEmbeddedServletContainer} to
@ -45,7 +48,12 @@ class TomcatEmbeddedContext extends StandardContext {
if (classLoader != null) { if (classLoader != null) {
existingLoader = ClassUtils.overrideThreadContextClassLoader(classLoader); existingLoader = ClassUtils.overrideThreadContextClassLoader(classLoader);
} }
if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage", null)) {
super.loadOnStartup(findChildren()); super.loadOnStartup(findChildren());
}
else {
callSuper(this, "loadOnStartup", findChildren(), Container[].class);
}
if (existingLoader != null) { if (existingLoader != null) {
ClassUtils.overrideThreadContextClassLoader(existingLoader); ClassUtils.overrideThreadContextClassLoader(existingLoader);
} }
@ -59,4 +67,10 @@ class TomcatEmbeddedContext extends StandardContext {
return this.starter; return this.starter;
} }
private void callSuper(Object target, String name, Object value, Class<?> type) {
Method method = ReflectionUtils.findMethod(target.getClass().getSuperclass(),
name, type);
ReflectionUtils.invokeMethod(method, target, value);
}
} }