From e4566c11b8fb3fa5d755339d022dbbc95e910f9c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 22 Jan 2021 15:22:51 +0000 Subject: [PATCH] Apply PathPatternParser also to BeanNameUrlHandlerMapping Closes gh-26414 --- .../annotation/WebMvcConfigurationSupport.java | 12 +++++++++++- .../DelegatingWebMvcConfigurationTests.java | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 4995b3f28f..17c1c10fc8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -514,6 +514,16 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv BeanNameUrlHandlerMapping mapping = new BeanNameUrlHandlerMapping(); mapping.setOrder(2); + + PathMatchConfigurer pathConfig = getPathMatchConfigurer(); + if (pathConfig.getPatternParser() != null) { + mapping.setPatternParser(pathConfig.getPatternParser()); + } + else { + mapping.setUrlPathHelper(pathConfig.getUrlPathHelperOrDefault()); + mapping.setPathMatcher(pathConfig.getPathMatcherOrDefault()); + } + mapping.setInterceptors(getInterceptors(conversionService, resourceUrlProvider)); mapping.setCorsConfigurations(getCorsConfigurations()); return mapping; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java index 9393f5d6bf..0b4e1d188c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -38,6 +38,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.servlet.HandlerExceptionResolver; +import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver; @@ -332,6 +333,14 @@ public class DelegatingWebMvcConfigurationTests { assertThat(mapping.getPatternParser()).isSameAs(patternParser); configAssertion.accept(mapping.getUrlPathHelper(), mapping.getPathMatcher()); + BeanNameUrlHandlerMapping beanNameMapping = webMvcConfig.beanNameHandlerMapping( + webMvcConfig.mvcConversionService(), + webMvcConfig.mvcResourceUrlProvider()); + + assertThat(beanNameMapping).isNotNull(); + assertThat(beanNameMapping.getPatternParser()).isSameAs(patternParser); + configAssertion.accept(beanNameMapping.getUrlPathHelper(), mapping.getPathMatcher()); + assertThat(webMvcConfig.mvcResourceUrlProvider().getUrlPathHelper()).isSameAs(pathHelper); assertThat(webMvcConfig.mvcResourceUrlProvider().getPathMatcher()).isSameAs(pathMatcher); } -- GitLab