Skip to content

Commit 6121da9

Browse files
committed
Working on SPR-5631 - Implicit /** mapping on type-level @RequestMapping
1 parent 4fb901c commit 6121da9

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,19 @@ protected String[] determineUrlsForHandler(String beanName) {
110110
// @RequestMapping found at type level
111111
this.cachedMappings.put(handlerType, mapping);
112112
Set<String> urls = new LinkedHashSet<String>();
113-
String[] paths = mapping.value();
114-
if (paths.length > 0) {
113+
String[] typeLevelPaths = mapping.value();
114+
if (typeLevelPaths.length > 0) {
115115
// @RequestMapping specifies paths at type level
116-
for (String path : paths) {
117-
addUrlsForPath(urls, path);
116+
String[] methodLevelPaths = determineUrlsForHandlerMethods(handlerType);
117+
for (String typeLevelPath : typeLevelPaths) {
118+
if (!typeLevelPath.startsWith("/")) {
119+
typeLevelPath = "/" + typeLevelPath;
120+
}
121+
for (String methodLevelPath : methodLevelPaths) {
122+
String combinedPath = getPathMatcher().combine(typeLevelPath, methodLevelPath);
123+
addUrlsForPath(urls, combinedPath);
124+
}
125+
addUrlsForPath(urls, typeLevelPath);
118126
}
119127
return StringUtils.toStringArray(urls);
120128
}

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2002-2009 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.web.servlet.mvc.annotation;
218

319
import java.io.IOException;
@@ -8,8 +24,8 @@
824
import javax.servlet.http.HttpServletResponse;
925

1026
import static org.junit.Assert.*;
11-
import org.junit.Test;
1227
import org.junit.Ignore;
28+
import org.junit.Test;
1329

1430
import org.springframework.beans.BeansException;
1531
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -73,7 +89,6 @@ public void ambiguous() throws Exception {
7389
}
7490

7591
@Test
76-
@Ignore("In progress")
7792
public void relative() throws Exception {
7893
initServlet(RelativePathUriTemplateController.class);
7994

@@ -120,7 +135,6 @@ public void explicitSubPath() throws Exception {
120135
}
121136

122137
@Test
123-
@Ignore("In progress")
124138
public void implicitSubPath() throws Exception {
125139
initServlet(ImplicitSubPathController.class);
126140

0 commit comments

Comments
 (0)