diff --git a/org.springframework.core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java b/org.springframework.core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java
index 5f256ad435f..e0a1aba156e 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java
@@ -44,7 +44,8 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
* 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.
+ * 'considerMetaAnnotations' argument. The filter will
+ * not match interfaces.
* @param annotationType the annotation type to match
*/
public AnnotationTypeFilter(Class extends Annotation> annotationType) {
@@ -53,11 +54,22 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
/**
* 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) {
- super(annotationType.isAnnotationPresent(Inherited.class), false);
+ 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;
}
diff --git a/org.springframework.core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java b/org.springframework.core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java
index 3d086d2bc33..68841aca1db 100644
--- a/org.springframework.core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java
+++ b/org.springframework.core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2011 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,10 +18,8 @@ package org.springframework.core.type;
import java.lang.annotation.Inherited;
-import junit.framework.TestCase;
-
-import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
@@ -31,7 +29,7 @@ import org.springframework.stereotype.Component;
* @author Juergen Hoeller
*/
public class AnnotationTypeFilterTests extends TestCase {
-
+
public void testDirectAnnotationMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponent";
@@ -52,7 +50,7 @@ public class AnnotationTypeFilterTests extends TestCase {
assertFalse(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
-
+
public void testInheritedAnnotationFromBaseClassDoesMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponent";
@@ -73,7 +71,7 @@ public class AnnotationTypeFilterTests extends TestCase {
assertFalse(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
-
+
public void testNonAnnotatedClassDoesntMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
@@ -84,6 +82,17 @@ public class AnnotationTypeFilterTests extends TestCase {
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
+ public void testMatchesInterfacesIfConfigured() throws Exception {
+
+ MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
+ String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponentInterface";
+ MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
+
+ AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class, false, true);
+
+ assertTrue(filter.match(metadataReader, metadataReaderFactory));
+ ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
+ }
// We must use a standalone set of types to ensure that no one else is loading them
// and interfering with ClassloadingAssertions.assertClassNotLoaded()