diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index 2d8b1e24293..88b77ab0739 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,7 +90,7 @@ public class HandlerMappingIntrospector * Return the configured HandlerMapping's. */ public List getHandlerMappings() { - return this.handlerMappings; + return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList()); } @@ -107,44 +107,6 @@ public class HandlerMappingIntrospector } } - private static List initHandlerMappings(ApplicationContext applicationContext) { - Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( - applicationContext, HandlerMapping.class, true, false); - if (!beans.isEmpty()) { - List mappings = new ArrayList<>(beans.values()); - AnnotationAwareOrderComparator.sort(mappings); - return Collections.unmodifiableList(mappings); - } - return Collections.unmodifiableList(initFallback(applicationContext)); - } - - private static List initFallback(ApplicationContext applicationContext) { - Properties props; - String path = "DispatcherServlet.properties"; - try { - Resource resource = new ClassPathResource(path, DispatcherServlet.class); - props = PropertiesLoaderUtils.loadProperties(resource); - } - catch (IOException ex) { - throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); - } - - String value = props.getProperty(HandlerMapping.class.getName()); - String[] names = StringUtils.commaDelimitedListToStringArray(value); - List result = new ArrayList<>(names.length); - for (String name : names) { - try { - Class clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader()); - Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz); - result.add((HandlerMapping) mapping); - } - catch (ClassNotFoundException ex) { - throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]"); - } - } - return result; - } - /** * Find the {@link HandlerMapping} that would handle the given request and @@ -204,6 +166,45 @@ public class HandlerMappingIntrospector } + private static List initHandlerMappings(ApplicationContext applicationContext) { + Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( + applicationContext, HandlerMapping.class, true, false); + if (!beans.isEmpty()) { + List mappings = new ArrayList<>(beans.values()); + AnnotationAwareOrderComparator.sort(mappings); + return Collections.unmodifiableList(mappings); + } + return Collections.unmodifiableList(initFallback(applicationContext)); + } + + private static List initFallback(ApplicationContext applicationContext) { + Properties props; + String path = "DispatcherServlet.properties"; + try { + Resource resource = new ClassPathResource(path, DispatcherServlet.class); + props = PropertiesLoaderUtils.loadProperties(resource); + } + catch (IOException ex) { + throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); + } + + String value = props.getProperty(HandlerMapping.class.getName()); + String[] names = StringUtils.commaDelimitedListToStringArray(value); + List result = new ArrayList<>(names.length); + for (String name : names) { + try { + Class clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader()); + Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz); + result.add((HandlerMapping) mapping); + } + catch (ClassNotFoundException ex) { + throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]"); + } + } + return result; + } + + /** * Request wrapper that ignores request attribute changes. */ @@ -215,7 +216,7 @@ public class HandlerMappingIntrospector @Override public void setAttribute(String name, Object value) { - // Ignore attribute change + // Ignore attribute change... } }