diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java index 55b7be8774b..1f5c6f42de7 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java @@ -132,22 +132,6 @@ public class ContextLoader { private static final String DEFAULT_STRATEGIES_PATH = "ContextLoader.properties"; - private static final Properties defaultStrategies; - - static { - // Load default strategy implementations from properties file. - // This is currently strictly internal and not meant to be customized - // by application developers. - try { - ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class); - defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); - } - catch (IOException ex) { - throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage()); - } - } - - /** * Map from (thread context) ClassLoader to corresponding 'current' WebApplicationContext. */ @@ -161,6 +145,8 @@ public class ContextLoader { @Nullable private static volatile WebApplicationContext currentContext; + @Nullable + private static Properties defaultStrategies; /** * The root WebApplicationContext instance that this loader manages. @@ -352,6 +338,18 @@ public class ContextLoader { } } else { + if (defaultStrategies == null) { + // Load default strategy implementations from properties file. + // This is currently strictly internal and not meant to be customized + // by application developers. + try { + ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class); + defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); + } + catch (IOException ex) { + throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage()); + } + } contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName()); try { return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());