#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:
committed by
Oliver Gierke
parent
1bd90991bd
commit
29b433445c
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user