1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public HandlerMappingIntrospector(ApplicationContext context) {
90
90
* Return the configured HandlerMapping's.
91
91
*/
92
92
public List <HandlerMapping > getHandlerMappings () {
93
- return this .handlerMappings ;
93
+ return ( this .handlerMappings != null ? this . handlerMappings : Collections . emptyList ()) ;
94
94
}
95
95
96
96
@@ -107,44 +107,6 @@ public void afterPropertiesSet() {
107
107
}
108
108
}
109
109
110
- private static List <HandlerMapping > initHandlerMappings (ApplicationContext applicationContext ) {
111
- Map <String , HandlerMapping > beans = BeanFactoryUtils .beansOfTypeIncludingAncestors (
112
- applicationContext , HandlerMapping .class , true , false );
113
- if (!beans .isEmpty ()) {
114
- List <HandlerMapping > mappings = new ArrayList <>(beans .values ());
115
- AnnotationAwareOrderComparator .sort (mappings );
116
- return Collections .unmodifiableList (mappings );
117
- }
118
- return Collections .unmodifiableList (initFallback (applicationContext ));
119
- }
120
-
121
- private static List <HandlerMapping > initFallback (ApplicationContext applicationContext ) {
122
- Properties props ;
123
- String path = "DispatcherServlet.properties" ;
124
- try {
125
- Resource resource = new ClassPathResource (path , DispatcherServlet .class );
126
- props = PropertiesLoaderUtils .loadProperties (resource );
127
- }
128
- catch (IOException ex ) {
129
- throw new IllegalStateException ("Could not load '" + path + "': " + ex .getMessage ());
130
- }
131
-
132
- String value = props .getProperty (HandlerMapping .class .getName ());
133
- String [] names = StringUtils .commaDelimitedListToStringArray (value );
134
- List <HandlerMapping > result = new ArrayList <>(names .length );
135
- for (String name : names ) {
136
- try {
137
- Class <?> clazz = ClassUtils .forName (name , DispatcherServlet .class .getClassLoader ());
138
- Object mapping = applicationContext .getAutowireCapableBeanFactory ().createBean (clazz );
139
- result .add ((HandlerMapping ) mapping );
140
- }
141
- catch (ClassNotFoundException ex ) {
142
- throw new IllegalStateException ("Could not find default HandlerMapping [" + name + "]" );
143
- }
144
- }
145
- return result ;
146
- }
147
-
148
110
149
111
/**
150
112
* Find the {@link HandlerMapping} that would handle the given request and
@@ -204,6 +166,45 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
204
166
}
205
167
206
168
169
+ private static List <HandlerMapping > initHandlerMappings (ApplicationContext applicationContext ) {
170
+ Map <String , HandlerMapping > beans = BeanFactoryUtils .beansOfTypeIncludingAncestors (
171
+ applicationContext , HandlerMapping .class , true , false );
172
+ if (!beans .isEmpty ()) {
173
+ List <HandlerMapping > mappings = new ArrayList <>(beans .values ());
174
+ AnnotationAwareOrderComparator .sort (mappings );
175
+ return Collections .unmodifiableList (mappings );
176
+ }
177
+ return Collections .unmodifiableList (initFallback (applicationContext ));
178
+ }
179
+
180
+ private static List <HandlerMapping > initFallback (ApplicationContext applicationContext ) {
181
+ Properties props ;
182
+ String path = "DispatcherServlet.properties" ;
183
+ try {
184
+ Resource resource = new ClassPathResource (path , DispatcherServlet .class );
185
+ props = PropertiesLoaderUtils .loadProperties (resource );
186
+ }
187
+ catch (IOException ex ) {
188
+ throw new IllegalStateException ("Could not load '" + path + "': " + ex .getMessage ());
189
+ }
190
+
191
+ String value = props .getProperty (HandlerMapping .class .getName ());
192
+ String [] names = StringUtils .commaDelimitedListToStringArray (value );
193
+ List <HandlerMapping > result = new ArrayList <>(names .length );
194
+ for (String name : names ) {
195
+ try {
196
+ Class <?> clazz = ClassUtils .forName (name , DispatcherServlet .class .getClassLoader ());
197
+ Object mapping = applicationContext .getAutowireCapableBeanFactory ().createBean (clazz );
198
+ result .add ((HandlerMapping ) mapping );
199
+ }
200
+ catch (ClassNotFoundException ex ) {
201
+ throw new IllegalStateException ("Could not find default HandlerMapping [" + name + "]" );
202
+ }
203
+ }
204
+ return result ;
205
+ }
206
+
207
+
207
208
/**
208
209
* Request wrapper that ignores request attribute changes.
209
210
*/
@@ -215,7 +216,7 @@ public RequestAttributeChangeIgnoringWrapper(HttpServletRequest request) {
215
216
216
217
@ Override
217
218
public void setAttribute (String name , Object value ) {
218
- // Ignore attribute change
219
+ // Ignore attribute change...
219
220
}
220
221
}
221
222
0 commit comments