Rely on presence of Servlet 2.5's ServletContext.getContextPath()

This commit is contained in:
Juergen Hoeller
2013-11-20 14:50:32 +01:00
parent 2ea5360b82
commit 0de112198e
4 changed files with 10 additions and 56 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.web.context;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -368,15 +367,8 @@ public class ContextLoader {
}
else {
// Generate default id...
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getServletContextName()));
}
else {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getContextPath()));
}
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getContextPath()));
}
}
@@ -470,7 +462,7 @@ public class ContextLoader {
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
determineContextInitializerClasses(servletContext);
if (initializerClasses.size() == 0) {
if (initializerClasses.isEmpty()) {
// no ApplicationContextInitializers have been declared -> nothing to do
return;
}
@@ -494,10 +486,10 @@ public class ContextLoader {
ConfigurableEnvironment env = applicationContext.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment)env).initPropertySources(servletContext, null);
((ConfigurableWebEnvironment) env).initPropertySources(servletContext, null);
}
Collections.sort(initializerInstances, new AnnotationAwareOrderComparator());
AnnotationAwareOrderComparator.sort(initializerInstances);
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
initializer.initialize(applicationContext);
}

View File

@@ -140,17 +140,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
@Override
public String getApplicationName() {
if (this.servletContext == null) {
return "";
}
if (this.servletContext.getMajorVersion() == 2 && this.servletContext.getMinorVersion() < 5) {
String name = this.servletContext.getServletContextName();
return (name != null ? name : "");
}
else {
// Servlet 2.5 available
return this.servletContext.getContextPath();
}
return (this.servletContext != null ? this.servletContext.getContextPath() : "");
}
/**

View File

@@ -28,7 +28,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.context.Theme;
import org.springframework.ui.context.ThemeSource;
import org.springframework.ui.context.support.UiApplicationContextUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.ConfigurableWebApplicationContext;
@@ -128,17 +127,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext
@Override
public String getApplicationName() {
if (this.servletContext == null) {
return "";
}
if (this.servletContext.getMajorVersion() == 2 && this.servletContext.getMinorVersion() < 5) {
String name = this.servletContext.getServletContextName();
return (name != null ? name : "");
}
else {
// Servlet 2.5 available
return this.servletContext.getContextPath();
}
return (this.servletContext != null ? this.servletContext.getContextPath() : "");
}
/**