diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryComponentProvider.java b/src/main/java/org/springframework/data/repository/config/RepositoryComponentProvider.java index 124e08ba5..3ac9d72c3 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryComponentProvider.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryComponentProvider.java @@ -1,17 +1,14 @@ package org.springframework.data.repository.config; import java.io.IOException; -import java.lang.annotation.Annotation; -import java.lang.annotation.Inherited; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter; +import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.TypeFilter; import org.springframework.data.repository.NoRepositoryBean; @@ -25,6 +22,7 @@ import org.springframework.util.Assert; * interface. Skips interfaces annotated with {@link NoRepositoryBean}. * * @author Oliver Gierke + * @author Thomas Darimont */ class RepositoryComponentProvider extends ClassPathScanningCandidateComponentProvider { @@ -117,82 +115,6 @@ class RepositoryComponentProvider extends ClassPathScanningCandidateComponentPro } } - // Copy of Spring's AnnotationTypeFilter until SPR-8336 gets resolved. - - /** - * A simple filter which matches classes with a given annotation, checking inherited annotations as well. - *
- * The matching logic mirrors that of Class.isAnnotationPresent().
- *
- * @author Mark Fisher
- * @author Ramnivas Laddad
- * @author Juergen Hoeller
- * @since 2.5
- */
- private static class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter {
-
- private final Class extends Annotation> annotationType;
-
- private final boolean considerMetaAnnotations;
-
- /**
- * Create a new AnnotationTypeFilter for the given annotation type. This filter will also match meta-annotations. To
- * disable the meta-annotation matching, use the constructor that accepts a ' considerMetaAnnotations'
- * argument. The filter will not match interfaces.
- *
- * @param annotationType the annotation type to match
- */
- public AnnotationTypeFilter(Class extends Annotation> annotationType) {
- this(annotationType, true);
- }
-
- /**
- * Create a new AnnotationTypeFilter for the given annotation type. The filter will not match interfaces.
- *
- * @param annotationType the annotation type to match
- * @param considerMetaAnnotations whether to also match on meta-annotations
- */
- public AnnotationTypeFilter(Class extends Annotation> annotationType, boolean considerMetaAnnotations) {
- this(annotationType, considerMetaAnnotations, false);
- }
-
- /**
- * Create a new {@link AnnotationTypeFilter} for the given annotation type.
- *
- * @param annotationType the annotation type to match
- * @param considerMetaAnnotations whether to also match on meta-annotations
- * @param considerInterfaces whether to also match interfaces
- */
- public AnnotationTypeFilter(Class extends Annotation> annotationType, boolean considerMetaAnnotations,
- boolean considerInterfaces) {
- super(annotationType.isAnnotationPresent(Inherited.class), considerInterfaces);
- this.annotationType = annotationType;
- this.considerMetaAnnotations = considerMetaAnnotations;
- }
-
- @Override
- protected boolean matchSelf(MetadataReader metadataReader) {
- AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
- return metadata.hasAnnotation(this.annotationType.getName())
- || (this.considerMetaAnnotations && metadata.hasMetaAnnotation(this.annotationType.getName()));
- }
-
- @Override
- protected Boolean matchSuperClass(String superClassName) {
- if (Object.class.getName().equals(superClassName)) {
- return Boolean.FALSE;
- } else if (superClassName.startsWith("java.")) {
- try {
- Class> clazz = getClass().getClassLoader().loadClass(superClassName);
- return (clazz.getAnnotation(this.annotationType) != null);
- } catch (ClassNotFoundException ex) {
- // Class not found - can't determine a match that way.
- }
- }
- return null;
- }
- }
-
/**
* Helper class to create a {@link TypeFilter} that matches if all the delegates match.
*