Check all HandlerMapping beans for named mappings

Related to (but not required by) SPR-16336.
This commit is contained in:
Rossen Stoyanchev 2018-06-14 19:16:39 -04:00
parent dad9ed83b7
commit e6fef9555d
1 changed files with 9 additions and 3 deletions

View File

@ -444,9 +444,15 @@ public class MvcUriComponentsBuilder {
*/
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
WebApplicationContext wac = getWebApplicationContext();
Assert.notNull(wac, "Cannot lookup handler method mappings without WebApplicationContext");
RequestMappingInfoHandlerMapping mapping = wac.getBean(RequestMappingInfoHandlerMapping.class);
List<HandlerMethod> handlerMethods = mapping.getHandlerMethodsForMappingName(name);
Assert.notNull(wac, "No WebApplicationContext. ");
Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
List<HandlerMethod> handlerMethods = null;
for (RequestMappingInfoHandlerMapping mapping : map.values()) {
handlerMethods = mapping.getHandlerMethodsForMappingName(name);
if (handlerMethods != null) {
break;
}
}
if (handlerMethods == null) {
throw new IllegalArgumentException("Mapping not found: " + name);
}