diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index b1d9f85242..3a11cf8c78 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -157,6 +157,7 @@ import org.springframework.web.util.WebUtils; * @author Rob Harrop * @author Chris Beams * @author Rossen Stoyanchev + * @author Sebastien Deleuze * @see org.springframework.web.HttpRequestHandler * @see org.springframework.web.servlet.mvc.Controller * @see org.springframework.web.context.ContextLoaderListener @@ -280,20 +281,9 @@ public class DispatcherServlet extends FrameworkServlet { /** Additional logger to use when no mapped handler is found for a request. */ protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY); - 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, DispatcherServlet.class); - defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); - } - catch (IOException ex) { - throw new IllegalStateException("Could not load '" + DEFAULT_STRATEGIES_PATH + "': " + ex.getMessage()); - } - } + /** Store default strategy implementations. */ + @Nullable + private static Properties defaultStrategies; /** Detect all HandlerMappings or just expect "handlerMapping" bean?. */ private boolean detectAllHandlerMappings = true; @@ -869,6 +859,19 @@ public class DispatcherServlet extends FrameworkServlet { */ @SuppressWarnings("unchecked") protected List getDefaultStrategies(ApplicationContext context, Class strategyInterface) { + if (defaultStrategies == null) { + try { + // Load default strategy implementations from properties file. + // This is currently strictly internal and not meant to be customized + // by application developers. + ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, DispatcherServlet.class); + defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); + } + catch (IOException ex) { + throw new IllegalStateException("Could not load '" + DEFAULT_STRATEGIES_PATH + "': " + ex.getMessage()); + } + } + String key = strategyInterface.getName(); String value = defaultStrategies.getProperty(key); if (value != null) {