|
|
|
|
@@ -42,140 +42,140 @@ import org.springframework.context.annotation.ImportResource;
|
|
|
|
|
* @author Juergen Hoeller
|
|
|
|
|
*/
|
|
|
|
|
public class ImportResourceTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXml() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
|
|
|
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXml() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
|
|
|
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class);
|
|
|
|
|
assertEquals("myName", tb.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlConfig {
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlConfig {
|
|
|
|
|
@Value("${name}")
|
|
|
|
|
private String name;
|
|
|
|
|
public @Bean TestBean javaDeclaredBean() {
|
|
|
|
|
return new TestBean(this.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public @Bean TestBean javaDeclaredBean() {
|
|
|
|
|
return new TestBean(this.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithRelativePath() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
|
|
|
|
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithRelativePath() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
|
|
|
|
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class);
|
|
|
|
|
assertEquals("myName", tb.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlWithRelativePathConfig {
|
|
|
|
|
public @Bean TestBean javaDeclaredBean() {
|
|
|
|
|
return new TestBean("java.declared");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlWithRelativePathConfig {
|
|
|
|
|
public @Bean TestBean javaDeclaredBean() {
|
|
|
|
|
return new TestBean("java.declared");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlByConvention() {
|
|
|
|
|
ApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlByConventionConfig.class);
|
|
|
|
|
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlByConvention() {
|
|
|
|
|
ApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlByConventionConfig.class);
|
|
|
|
|
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
//@ImportXml
|
|
|
|
|
static class ImportXmlByConventionConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
//@ImportXml
|
|
|
|
|
static class ImportXmlByConventionConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlIsInheritedFromSuperclassDeclarations() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlIsInheritedFromSuperclassDeclarations() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlIsMergedFromSuperclassDeclarations() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
|
|
|
|
|
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean"));
|
|
|
|
|
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlIsMergedFromSuperclassDeclarations() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
|
|
|
|
|
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean"));
|
|
|
|
|
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class FirstLevelSubConfig extends BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
static class FirstLevelSubConfig extends BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/SecondLevelSubConfig-context.xml")
|
|
|
|
|
static class SecondLevelSubConfig extends BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/SecondLevelSubConfig-context.xml")
|
|
|
|
|
static class SecondLevelSubConfig extends BaseConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithNamespaceConfig() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
|
|
|
|
|
Object bean = ctx.getBean("proxiedXmlBean");
|
|
|
|
|
assertTrue(AopUtils.isAopProxy(bean));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithNamespaceConfig() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
|
|
|
|
|
Object bean = ctx.getBean("proxiedXmlBean");
|
|
|
|
|
assertTrue(AopUtils.isAopProxy(bean));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlWithAopNamespace-context.xml")
|
|
|
|
|
static class ImportXmlWithAopNamespaceConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlWithAopNamespace-context.xml")
|
|
|
|
|
static class ImportXmlWithAopNamespaceConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Aspect
|
|
|
|
|
static class AnAspect {
|
|
|
|
|
@Before("execution(* test.beans.TestBean.*(..))")
|
|
|
|
|
public void advice() { }
|
|
|
|
|
}
|
|
|
|
|
@Aspect
|
|
|
|
|
static class AnAspect {
|
|
|
|
|
@Before("execution(* test.beans.TestBean.*(..))")
|
|
|
|
|
public void advice() { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithAutowiredConfig() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
|
|
|
|
|
String name = ctx.getBean("xmlBeanName", String.class);
|
|
|
|
|
assertThat(name, equalTo("xml.declared"));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportXmlWithAutowiredConfig() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
|
|
|
|
|
String name = ctx.getBean("xmlBeanName", String.class);
|
|
|
|
|
assertThat(name, equalTo("xml.declared"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlAutowiredConfig {
|
|
|
|
|
@Autowired TestBean xmlDeclaredBean;
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
|
|
|
|
static class ImportXmlAutowiredConfig {
|
|
|
|
|
@Autowired TestBean xmlDeclaredBean;
|
|
|
|
|
|
|
|
|
|
public @Bean String xmlBeanName() {
|
|
|
|
|
return xmlDeclaredBean.getName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public @Bean String xmlBeanName() {
|
|
|
|
|
return xmlDeclaredBean.getName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportNonXmlResource() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportNonXmlResource() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportNonXmlResourceConfig-context.properties",
|
|
|
|
|
reader=PropertiesBeanDefinitionReader.class)
|
|
|
|
|
static class ImportNonXmlResourceConfig {
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportNonXmlResourceConfig-context.properties",
|
|
|
|
|
reader=PropertiesBeanDefinitionReader.class)
|
|
|
|
|
static class ImportNonXmlResourceConfig {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6327
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportDifferentResourceTypes() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
@Ignore // TODO: SPR-6327
|
|
|
|
|
@Test
|
|
|
|
|
public void testImportDifferentResourceTypes() {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class);
|
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
|
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml",
|
|
|
|
|
reader=XmlBeanDefinitionReader.class)
|
|
|
|
|
static class SubResourceConfig extends ImportNonXmlResourceConfig {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Configuration
|
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml",
|
|
|
|
|
reader=XmlBeanDefinitionReader.class)
|
|
|
|
|
static class SubResourceConfig extends ImportNonXmlResourceConfig {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|