Rely on presence of Servlet 2.5's ServletContext.getContextPath()
This commit is contained in:
parent
2ea5360b82
commit
0de112198e
|
@ -18,7 +18,6 @@ package org.springframework.web.context;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -368,15 +367,8 @@ public class ContextLoader {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Generate default id...
|
// Generate default id...
|
||||||
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
|
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
|
||||||
// Servlet <= 2.4: resort to name specified in web.xml, if any.
|
ObjectUtils.getDisplayString(sc.getContextPath()));
|
||||||
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
|
|
||||||
ObjectUtils.getDisplayString(sc.getServletContextName()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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) {
|
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
|
||||||
List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
|
List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
|
||||||
determineContextInitializerClasses(servletContext);
|
determineContextInitializerClasses(servletContext);
|
||||||
if (initializerClasses.size() == 0) {
|
if (initializerClasses.isEmpty()) {
|
||||||
// no ApplicationContextInitializers have been declared -> nothing to do
|
// no ApplicationContextInitializers have been declared -> nothing to do
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -494,10 +486,10 @@ public class ContextLoader {
|
||||||
|
|
||||||
ConfigurableEnvironment env = applicationContext.getEnvironment();
|
ConfigurableEnvironment env = applicationContext.getEnvironment();
|
||||||
if (env instanceof ConfigurableWebEnvironment) {
|
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) {
|
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
|
||||||
initializer.initialize(applicationContext);
|
initializer.initialize(applicationContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,17 +140,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getApplicationName() {
|
public String getApplicationName() {
|
||||||
if (this.servletContext == null) {
|
return (this.servletContext != null ? this.servletContext.getContextPath() : "");
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
import org.springframework.ui.context.Theme;
|
import org.springframework.ui.context.Theme;
|
||||||
import org.springframework.ui.context.ThemeSource;
|
import org.springframework.ui.context.ThemeSource;
|
||||||
import org.springframework.ui.context.support.UiApplicationContextUtils;
|
import org.springframework.ui.context.support.UiApplicationContextUtils;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
|
@ -128,17 +127,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getApplicationName() {
|
public String getApplicationName() {
|
||||||
if (this.servletContext == null) {
|
return (this.servletContext != null ? this.servletContext.getContextPath() : "");
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.springframework.web.servlet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -617,23 +615,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Generate default id...
|
// Generate default id...
|
||||||
ServletContext sc = getServletContext();
|
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
|
||||||
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
|
ObjectUtils.getDisplayString(getServletContext().getContextPath()) + "/" + getServletName());
|
||||||
// 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 +
|
|
||||||
"." + getServletName());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Servlet 2.5's getContextPath available!
|
|
||||||
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
|
|
||||||
ObjectUtils.getDisplayString(sc.getContextPath()) + "/" + getServletName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +686,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
||||||
this.contextInitializers.add(initializer);
|
this.contextInitializers.add(initializer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(this.contextInitializers, new AnnotationAwareOrderComparator());
|
AnnotationAwareOrderComparator.sort(this.contextInitializers);
|
||||||
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
|
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
|
||||||
initializer.initialize(wac);
|
initializer.initialize(wac);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue