diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
index 8820f1cda..b7993a1b2 100644
--- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
+++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2014 the original author or authors.
+ * Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.data.annotation.AccessType;
import org.springframework.data.annotation.AccessType.Type;
import org.springframework.data.annotation.Id;
@@ -223,14 +223,15 @@ public abstract class AnnotationBasedPersistentProperty
> implements MutablePersistentEntity {
@@ -284,7 +285,7 @@ public class BasicPersistentEntity> implement
*/
public Object getTypeAlias() {
- TypeAlias alias = getType().getAnnotation(TypeAlias.class);
+ TypeAlias alias = AnnotatedElementUtils.findMergedAnnotation(getType(), TypeAlias.class);
return alias == null ? null : StringUtils.hasText(alias.value()) ? alias.value() : null;
}
@@ -366,7 +367,7 @@ public class BasicPersistentEntity> implement
return annotation;
}
- annotation = AnnotationUtils.findAnnotation(getType(), annotationType);
+ annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType);
annotationCache.put(annotationType, annotation);
return annotation;
diff --git a/src/main/java/org/springframework/data/util/AnnotationDetectionFieldCallback.java b/src/main/java/org/springframework/data/util/AnnotationDetectionFieldCallback.java
index d2604fbd3..ddd62ebbf 100755
--- a/src/main/java/org/springframework/data/util/AnnotationDetectionFieldCallback.java
+++ b/src/main/java/org/springframework/data/util/AnnotationDetectionFieldCallback.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2014 the original author or authors.
+ * Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.data.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;
@@ -27,6 +28,7 @@ import org.springframework.util.ReflectionUtils.FieldCallback;
* afterwards.
*
* @author Oliver Gierke
+ * @author Christoph Strobl
*/
public class AnnotationDetectionFieldCallback implements FieldCallback {
@@ -54,7 +56,7 @@ public class AnnotationDetectionFieldCallback implements FieldCallback {
return;
}
- Annotation annotation = field.getAnnotation(annotationType);
+ Annotation annotation = AnnotatedElementUtils.findMergedAnnotation(field, annotationType);
if (annotation != null) {
diff --git a/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java b/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java
index 82c1ac6fa..418a29f94 100644
--- a/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java
+++ b/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.data.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
-import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils.MethodCallback;
@@ -26,6 +26,7 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
* {@link MethodCallback} to find annotations of a given type.
*
* @author Oliver Gierke
+ * @author Christoph Strobl
*/
public class AnnotationDetectionMethodCallback implements MethodCallback {
@@ -94,7 +95,7 @@ public class AnnotationDetectionMethodCallback implements
return;
}
- A foundAnnotation = AnnotationUtils.findAnnotation(method, annotationType);
+ A foundAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, annotationType);
if (foundAnnotation != null) {
diff --git a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java
index 8e7e14d1d..7011f57c7 100644
--- a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java
+++ b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.annotation.AccessType;
import org.springframework.data.annotation.AccessType.Type;
import org.springframework.data.annotation.Id;
@@ -220,6 +222,37 @@ public class AnnotationBasedPersistentPropertyUnitTests, Annotation> cache = getAnnotationCache(property);
+ assertThat(cache.containsKey(MyComposedAnnotationUsingAliasFor.class), is(true));
+ assertThat(cache.containsKey(MyAnnotation.class), is(false));
+
+ // Assert meta annotation is found and cached
+ MyAnnotation annotation = property.findAnnotation(MyAnnotation.class);
+ assertThat(annotation, is(notNullValue()));
+ assertThat(cache.containsKey(MyAnnotation.class), is(true));
+ }
+
+ /**
+ * @see DATACMNS-825
+ */
+ @Test
+ public void composedAnnotationWithAliasShouldHaveSynthesizedAttributeValues() {
+
+ SamplePersistentProperty property = entity.getPersistentProperty("metaAliased");
+
+ MyAnnotation annotation = property.findAnnotation(MyAnnotation.class);
+ assertThat(AnnotationUtils.getValue(annotation), is((Object) "spring"));
+ }
+
@SuppressWarnings("unchecked")
private Map, Annotation> getAnnotationCache(SamplePersistentProperty property) {
return (Map, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");
@@ -248,6 +281,8 @@ public class AnnotationBasedPersistentPropertyUnitTests> {
assertThat(entity.getPropertyAccessor(new Subtype()), is(notNullValue()));
}
+ /**
+ * @see DATACMNS-825
+ */
+ @Test
+ public void returnsTypeAliasIfAnnotatedUsingComposedAnnotation() {
+
+ PersistentEntity entity = createEntity(
+ AliasEntityUsingComposedAnnotation.class);
+ assertThat(entity.getTypeAlias(), is((Object) "bar"));
+ }
+
private BasicPersistentEntity createEntity(Class type) {
return createEntity(type, null);
}
@@ -251,5 +265,18 @@ public class BasicPersistentEntityUnitTests> {
}
}
+ @Retention(RetentionPolicy.RUNTIME)
+ @TypeAlias("foo")
+ static @interface ComposedTypeAlias {
+
+ @AliasFor(annotation = TypeAlias.class, attribute = "value")
+ String name() default "bar";
+ }
+
+ @ComposedTypeAlias
+ static class AliasEntityUsingComposedAnnotation {
+
+ }
+
static class Subtype extends Entity {}
}