#46 - AnnotationMappingDiscoverer now deals with missing method mapping.

If a method level @RequestMapping is not carrying a value we now fall back to the type level mapping as Spring MVC does. Before the fix, providing no mapping lead to an ArrayIndexOutOfBoundsException.
This commit is contained in:
Alexander Chilingaryan
2013-02-13 15:30:46 +04:00
committed by Oliver Gierke
parent 1bd90991bd
commit 29b433445c
2 changed files with 18 additions and 0 deletions

View File

@@ -88,6 +88,11 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
}
String typeMapping = getMapping(method.getDeclaringClass());
if (mapping == null || mapping.length == 0) {
return typeMapping;
}
return typeMapping == null ? mapping[0] : typeMapping + mapping[0];
}

View File

@@ -60,11 +60,24 @@ public class AnnotationMappingDiscovererUnitTest {
assertThat(discoverer.getMapping(method), is("/method"));
}
/**
* @see #46
*/
@Test
public void treatsMissingMethodMappingAsEmptyMapping() throws Exception {
Method method = MyController.class.getMethod("noMethodMapping");
assertThat(discoverer.getMapping(method), is("/type"));
}
@RequestMapping("/type")
interface MyController {
@RequestMapping("/method")
void method();
@RequestMapping
void noMethodMapping();
}
interface ControllerWithoutTypeLevelMapping {