diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java index 645203933a..d7bed91502 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java @@ -101,9 +101,12 @@ abstract class ConfigurationClassUtils { } public static boolean isLiteConfigurationCandidate(AnnotationMetadata metadata) { - return !metadata.isInterface() && // not an interface or an annotation - (metadata.isAnnotated(Component.class.getName()) || - metadata.hasAnnotatedMethods(Bean.class.getName())); + if(metadata.isInterface()) { + return false; // do not consider an interface or an annotation + } + return metadata.isAnnotated(Import.class.getName()) || + metadata.isAnnotated(Component.class.getName()) || + metadata.hasAnnotatedMethods(Bean.class.getName()); } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportAnnotationDetectionTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportAnnotationDetectionTests.java index 7e5570ee4e..b24041cf92 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportAnnotationDetectionTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportAnnotationDetectionTests.java @@ -25,12 +25,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.junit.Test; +import org.springframework.stereotype.Service; import org.springframework.tests.sample.beans.TestBean; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import static org.junit.Assert.*; + /** * Tests that @Import may be used both as a locally declared and meta-declared * annotation, that all declarations are processed, and that any local declaration @@ -70,6 +73,16 @@ public class ImportAnnotationDetectionTests { assertThat(ctx.getBean("testBean2", TestBean.class).getName(), is("2a")); } + @Test + public void importFromBean() throws Exception { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + ctx.register(ImportFromBean.class); + ctx.refresh(); + assertThat(ctx.containsBean("importAnnotationDetectionTests.ImportFromBean"), is(true)); + assertThat(ctx.containsBean("testBean1"), is(true)); + assertThat(ctx.getBean("testBean1", TestBean.class).getName(), is("1")); + } + @Configuration @MetaImport1 @MetaImport2 @@ -136,4 +149,9 @@ public class ImportAnnotationDetectionTests { return new TestBean("3"); } } + + @MetaImport1 + static class ImportFromBean { + + } }