Browse Source

restored compatibility with Servlet 2.4 containers on all VMs (SPR-7044)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3184 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
bae7c867e9
  1. 18
      org.springframework.web/src/main/java/org/springframework/web/context/ContextLoader.java

18
org.springframework.web/src/main/java/org/springframework/web/context/ContextLoader.java

@ -34,6 +34,7 @@ import org.springframework.context.access.ContextSingletonBeanFactoryLocator; @@ -34,6 +34,7 @@ import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
* Performs the actual initialization work for the root application context.
@ -253,16 +254,19 @@ public class ContextLoader { @@ -253,16 +254,19 @@ public class ContextLoader {
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = sc.getServletContextName();
if (servletContextName != null) {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName);
}
else {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX);
}
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(servletContextName));
}
else {
// Servlet 2.5's getContextPath available!
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + sc.getContextPath());
try {
String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(sc);
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(contextPath));
}
catch (Exception ex) {
throw new IllegalStateException("Failed to invoke Servlet 2.5 getContextPath method", ex);
}
}
wac.setParent(parent);

Loading…
Cancel
Save