Consider @Import classes as lite @Configuration

Allow classes that are annotated with @Import to be considered as 'lite'
@Configuration candidates. Allows the AnnotationConfigApplicationContext
to directly register @Import beans even if they are not @Components.

Issue: SPR-10533
This commit is contained in:
Phillip Webb
2013-05-02 09:41:20 -07:00
parent d91ffb6a59
commit 71f6da673a
2 changed files with 24 additions and 3 deletions

View File

@@ -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 {
}
}