Skip to content

Commit e4566c1

Browse files
committed
Apply PathPatternParser also to BeanNameUrlHandlerMapping
Closes gh-26414
1 parent 9d8910d commit e4566c1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -514,6 +514,16 @@ public BeanNameUrlHandlerMapping beanNameHandlerMapping(
514514

515515
BeanNameUrlHandlerMapping mapping = new BeanNameUrlHandlerMapping();
516516
mapping.setOrder(2);
517+
518+
PathMatchConfigurer pathConfig = getPathMatchConfigurer();
519+
if (pathConfig.getPatternParser() != null) {
520+
mapping.setPatternParser(pathConfig.getPatternParser());
521+
}
522+
else {
523+
mapping.setUrlPathHelper(pathConfig.getUrlPathHelperOrDefault());
524+
mapping.setPathMatcher(pathConfig.getPathMatcherOrDefault());
525+
}
526+
517527
mapping.setInterceptors(getInterceptors(conversionService, resourceUrlProvider));
518528
mapping.setCorsConfigurations(getCorsConfigurations());
519529
return mapping;

spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
3939
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
4040
import org.springframework.web.servlet.HandlerExceptionResolver;
41+
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
4142
import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite;
4243
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
4344
import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver;
@@ -332,6 +333,14 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
332333
assertThat(mapping.getPatternParser()).isSameAs(patternParser);
333334
configAssertion.accept(mapping.getUrlPathHelper(), mapping.getPathMatcher());
334335

336+
BeanNameUrlHandlerMapping beanNameMapping = webMvcConfig.beanNameHandlerMapping(
337+
webMvcConfig.mvcConversionService(),
338+
webMvcConfig.mvcResourceUrlProvider());
339+
340+
assertThat(beanNameMapping).isNotNull();
341+
assertThat(beanNameMapping.getPatternParser()).isSameAs(patternParser);
342+
configAssertion.accept(beanNameMapping.getUrlPathHelper(), mapping.getPathMatcher());
343+
335344
assertThat(webMvcConfig.mvcResourceUrlProvider().getUrlPathHelper()).isSameAs(pathHelper);
336345
assertThat(webMvcConfig.mvcResourceUrlProvider().getPathMatcher()).isSameAs(pathMatcher);
337346
}

0 commit comments

Comments
 (0)