#186 - AnnotationMappingDiscoverer now uses first mapping in case multiple ones are defined.
This commit is contained in:
@@ -70,11 +70,6 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
|
||||
String[] mapping = getMappingFrom(findAnnotation(type, annotationType));
|
||||
|
||||
if (mapping.length > 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Multiple class level mappings defined on class %s!", type.getName()));
|
||||
}
|
||||
|
||||
return mapping.length == 0 ? null : mapping[0];
|
||||
}
|
||||
|
||||
@@ -100,12 +95,6 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
Assert.notNull(method, "Method must not be null!");
|
||||
|
||||
String[] mapping = getMappingFrom(findAnnotation(method, annotationType));
|
||||
|
||||
if (mapping.length > 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Multiple method level mappings defined on method %s!", method.toString()));
|
||||
}
|
||||
|
||||
String typeMapping = getMapping(type);
|
||||
|
||||
if (mapping == null || mapping.length == 0) {
|
||||
|
||||
@@ -128,6 +128,17 @@ public class AnnotationMappingDiscovererUnitTest {
|
||||
assertThat(discoverer.getMapping(method), is("trailing/withslash"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #186
|
||||
*/
|
||||
@Test
|
||||
public void usesFirstMappingInCaseMultipleOnesAreDefined() throws Exception {
|
||||
|
||||
Method method = MultipleMappingsController.class.getMethod("method");
|
||||
|
||||
assertThat(discoverer.getMapping(method), is("/type/method"));
|
||||
}
|
||||
|
||||
@RequestMapping("/type")
|
||||
interface MyController {
|
||||
|
||||
@@ -197,4 +208,11 @@ public class AnnotationMappingDiscovererUnitTest {
|
||||
@RequestMapping("////withslash")
|
||||
void withslash();
|
||||
}
|
||||
|
||||
@RequestMapping({ "/type", "/typeAlias" })
|
||||
interface MultipleMappingsController {
|
||||
|
||||
@RequestMapping({ "/method", "/methodAlias" })
|
||||
void method();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,12 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
assertThat(link.getHref(), endsWith("/people"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void rejectsControllerWithMultipleMappings() {
|
||||
linkTo(InvalidController.class);
|
||||
/**
|
||||
* @see #186
|
||||
*/
|
||||
@Test
|
||||
public void usesFirstMappingInCaseMultipleOnesAreDefined() {
|
||||
assertThat(linkTo(InvalidController.class).withSelfRel().getHref(), endsWith("/persons"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user