Additional tests rounding out @ImportXml coverage
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2292 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
63dfad8214
commit
a502272b6b
|
|
@ -0,0 +1,3 @@
|
||||||
|
#Fri Nov 06 18:17:35 PST 2009
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.springframework.ide.eclipse.beans.core.ignoreMissingNamespaceHandler=false
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
#Fri Nov 06 18:17:35 PST 2009
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.springframework.ide.eclipse.core.builders.enable.aopreferencemodelbuilder=true
|
||||||
|
org.springframework.ide.eclipse.core.builders.enable.beanmetadatabuilder=true
|
||||||
|
org.springframework.ide.eclipse.core.builders.enable.osgibundleupdater=false
|
||||||
|
org.springframework.ide.eclipse.core.enable.project.preferences=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.server.quickfix.manifestvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.core.springvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.applicationSymbolicNameRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.applicationVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleActivationPolicyRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleActivatorRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleManifestVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleNameRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleSymbolicNameRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.exportPackageRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.importRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.parsingProblemsRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.requireBundleRule-com.springsource.server.ide.manifest.core.manifestvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.AvoidDriverManagerDataSource-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ImportElementsAtTopRulee-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ParentBeanSpecifiesAbstractClassRule-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.RefElementRule-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.TooManyBeansInFileRule-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UnnecessaryValueElementRule-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UseBeanInheritance-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.legacyxmlusage.jndiobjectfactory-com.springsource.sts.bestpractices.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importLibraryVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importPackageVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.requireBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.autowire.autowire-org.springframework.ide.eclipse.beans.core.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanAlias-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanClass-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanConstructorArgument-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinition-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinitionHolder-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanFactory-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanInitDestroyMethod-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanReference-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.methodOverride-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.parsingProblems-org.springframework.ide.eclipse.beans.core.beansvalidator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.requiredProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.toolAnnotation-org.springframework.ide.eclipse.beans.core.beansvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.core.springClasspath-org.springframework.ide.eclipse.core.springvalidator=false
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.action-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.actionstate-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attribute-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attributemapper-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.beanaction-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationaction-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationresult-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.exceptionhandler-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.import-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.inputattribute-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.mapping-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.outputattribute-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.set-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.state-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.subflowstate-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.transition-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.variable-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.webflowstate-org.springframework.ide.eclipse.webflow.core.validator=true
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
<enableImports><![CDATA[false]]></enableImports>
|
<enableImports><![CDATA[false]]></enableImports>
|
||||||
<configs>
|
<configs>
|
||||||
<config>src/test/java/org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml</config>
|
<config>src/test/java/org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml</config>
|
||||||
|
<config>src/test/java/org/springframework/context/annotation/configuration/SecondLevelSubConfig-context.xml</config>
|
||||||
|
<config>src/test/java/org/springframework/context/annotation/configuration/ImportXmlWithAopNamespace-context.xml</config>
|
||||||
</configs>
|
</configs>
|
||||||
<configSets>
|
<configSets>
|
||||||
</configSets>
|
</configSets>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||||
import org.springframework.beans.factory.annotation.Autowire;
|
import org.springframework.beans.factory.annotation.Autowire;
|
||||||
import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor;
|
import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor;
|
||||||
|
|
@ -39,7 +38,6 @@ import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
import org.springframework.core.type.MethodMetadata;
|
import org.springframework.core.type.MethodMetadata;
|
||||||
|
|
@ -92,6 +90,7 @@ class ConfigurationClassBeanDefinitionReader {
|
||||||
*/
|
*/
|
||||||
private void loadBeanDefinitionsForConfigurationClass(ConfigurationClass configClass) {
|
private void loadBeanDefinitionsForConfigurationClass(ConfigurationClass configClass) {
|
||||||
doLoadBeanDefinitionForConfigurationClass(configClass);
|
doLoadBeanDefinitionForConfigurationClass(configClass);
|
||||||
|
|
||||||
for (ConfigurationClassMethod method : configClass.getMethods()) {
|
for (ConfigurationClassMethod method : configClass.getMethods()) {
|
||||||
loadBeanDefinitionsForModelMethod(method);
|
loadBeanDefinitionsForModelMethod(method);
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +214,7 @@ class ConfigurationClassBeanDefinitionReader {
|
||||||
|
|
||||||
private void loadBeanDefinitionsFromXml(Set<String> xmlImports) {
|
private void loadBeanDefinitionsFromXml(Set<String> xmlImports) {
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.registry);
|
||||||
|
// TODO SPR-6310: qualify relatively pathed locations as done in AbstractContextLoader.modifyLocations
|
||||||
reader.loadBeanDefinitions(xmlImports.toArray(new String[]{}));
|
reader.loadBeanDefinitions(xmlImports.toArray(new String[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package org.springframework.context.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Inherited;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
@ -25,10 +26,9 @@ import java.lang.annotation.Target;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Documented
|
@Documented
|
||||||
|
@Inherited
|
||||||
public @interface ImportXml {
|
public @interface ImportXml {
|
||||||
|
|
||||||
String[] value();
|
String[] value();
|
||||||
|
|
||||||
Class<?> relativeTo() default void.class;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
<bean id="xmlDeclaredBean" class="org.springframework.beans.TestBean">
|
<bean id="xmlDeclaredBean" class="test.beans.TestBean">
|
||||||
<constructor-arg value="xml.declaraed"/>
|
<constructor-arg value="xml.declared"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,13 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -37,7 +41,7 @@ import test.beans.TestBean;
|
||||||
*/
|
*/
|
||||||
public class ImportXmlTests {
|
public class ImportXmlTests {
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWorks() {
|
public void testImportXml() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
|
||||||
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
||||||
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
|
|
@ -51,35 +55,89 @@ public class ImportXmlTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
@Ignore // TODO: SPR-6310
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWorksWithRelativePathing() {
|
public void testImportXmlWithRelativePath() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportsXmlWithRelativeTo.class);
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
|
||||||
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
|
||||||
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ImportXml(value="beans.xml", relativeTo=ImportXmlTests.class)
|
@ImportXml("ImportXmlConfig-context.xml")
|
||||||
static class ImportsXmlWithRelativeTo {
|
static class ImportXmlWithRelativePathConfig {
|
||||||
public @Bean TestBean javaDeclaredBean() {
|
public @Bean TestBean javaDeclaredBean() {
|
||||||
return new TestBean("java.declared");
|
return new TestBean("java.declared");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore // TODO: SPR-6310
|
||||||
@Test
|
@Test
|
||||||
public void testImportXmlWorksWithAutowired() {
|
public void testImportXmlByConvention() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AutowiredImportXml.class);
|
ApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlByConventionConfig.class);
|
||||||
String name = ctx.getBean("xmlBeanName", String.class);
|
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
|
||||||
assertThat(name, equalTo("xmlBean"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ImportXml(value="beans.xml", relativeTo=AutowiredImportXml.class)
|
//@ImportXml
|
||||||
static class AutowiredImportXml {
|
static class ImportXmlByConventionConfig {
|
||||||
|
}
|
||||||
|
|
||||||
|
@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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ImportXml("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
||||||
|
static class BaseConfig {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class FirstLevelSubConfig extends BaseConfig {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ImportXml("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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ImportXml("classpath:org/springframework/context/annotation/configuration/ImportXmlWithAopNamespace-context.xml")
|
||||||
|
static class ImportXmlWithAopNamespaceConfig {
|
||||||
|
}
|
||||||
|
|
||||||
|
@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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ImportXml(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml")
|
||||||
|
static class ImportXmlAutowiredConfig {
|
||||||
@Autowired TestBean xmlDeclaredBean;
|
@Autowired TestBean xmlDeclaredBean;
|
||||||
|
|
||||||
public @Bean String xmlBeanName() {
|
public @Bean String xmlBeanName() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<bean id="proxiedXmlBean" class="test.beans.TestBean"/>
|
||||||
|
|
||||||
|
<bean id="anAspect" class="org.springframework.context.annotation.configuration.ImportXmlTests$AnAspect"/>
|
||||||
|
|
||||||
|
<aop:aspectj-autoproxy>
|
||||||
|
<aop:include name="anAspect"/>
|
||||||
|
</aop:aspectj-autoproxy>
|
||||||
|
|
||||||
|
</beans>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<bean id="secondLevelXmlDeclaredBean" class="java.lang.Object"/>
|
||||||
|
|
||||||
|
</beans>
|
||||||
Loading…
Reference in New Issue