Merge branch '1.0.x'

pull/946/head
Phillip Webb 11 years ago
commit dbf75749a9

@ -0,0 +1,47 @@
package org.springframework.boot.context.embedded.tomcat;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.util.ClassUtils;
/**
* Tomcat {@link LifecycleListener} to initialize Jasper by calling the
* `JasperInitializer` used in Tomcat 8.
*
* @author Phillip Webb
*/
class JasperInitializerLifecycleListener implements LifecycleListener {
private static final String JASPER_INITIALIZER_CLASS = "org.apache.jasper.servlet.JasperInitializer";
private final ServletContextInitializerLifecycleListener delegate;
public JasperInitializerLifecycleListener() {
ServletContextInitializer initializer = getJasperInitializer();
if (initializer != null) {
this.delegate = new ServletContextInitializerLifecycleListener(initializer);
}
else {
this.delegate = null;
}
}
@Override
public void lifecycleEvent(LifecycleEvent event) {
if (this.delegate != null) {
this.delegate.lifecycleEvent(event);
}
}
private ServletContextInitializer getJasperInitializer() {
try {
Class<?> jasperClass = ClassUtils.forName(JASPER_INITIALIZER_CLASS, null);
return (ServletContextInitializer) jasperClass.newInstance();
}
catch (Exception ex) {
return null;
}
}
}

@ -230,6 +230,7 @@ public class TomcatEmbeddedServletContainerFactory extends
ServletContextInitializer[] initializers) { ServletContextInitializer[] initializers) {
context.addLifecycleListener(new ServletContextInitializerLifecycleListener( context.addLifecycleListener(new ServletContextInitializerLifecycleListener(
initializers)); initializers));
context.addLifecycleListener(new JasperInitializerLifecycleListener());
for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) { for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
context.addLifecycleListener(lifecycleListener); context.addLifecycleListener(lifecycleListener);
} }

@ -16,7 +16,11 @@
package org.springframework.boot.context.embedded.tomcat; package org.springframework.boot.context.embedded.tomcat;
import java.net.URL;
import org.apache.catalina.loader.WebappClassLoader; import org.apache.catalina.loader.WebappClassLoader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** /**
* Extension of Tomcat's {@link WebappClassLoader} that does not consider the * Extension of Tomcat's {@link WebappClassLoader} that does not consider the
@ -28,6 +32,9 @@ import org.apache.catalina.loader.WebappClassLoader;
*/ */
public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader { public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
private static final Log logger = LogFactory
.getLog(TomcatEmbeddedWebappClassLoader.class);
public TomcatEmbeddedWebappClassLoader() { public TomcatEmbeddedWebappClassLoader() {
super(); super();
} }
@ -78,6 +85,14 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader {
return (resultClass); return (resultClass);
} }
@Override
protected void addURL(URL url) {
// Ignore URLs added by the Tomcat 8 implementation (see gh-919)
if (logger.isTraceEnabled()) {
logger.trace("Ignoring request to add " + url + " to the tomcat classloader");
}
}
private Class<?> loadFromParent(String name) { private Class<?> loadFromParent(String name) {
if (this.parent == null) { if (this.parent == null) {
return null; return null;

Loading…
Cancel
Save