diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java index bab2d3879f..e503f1bca2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -118,16 +118,6 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume * @see #setEnvironment */ protected void doRegisterBeanDefinitions(Element root) { - String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE); - if (StringUtils.hasText(profileSpec)) { - Assert.state(this.environment != null, "Environment must be set for evaluating profiles"); - String[] specifiedProfiles = StringUtils.tokenizeToStringArray( - profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); - if (!this.environment.acceptsProfiles(specifiedProfiles)) { - return; - } - } - // Any nested elements will cause recursion in this method. In // order to propagate and preserve default-* attributes correctly, // keep track of the current (parent) delegate, which may be null. Create @@ -137,6 +127,18 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume BeanDefinitionParserDelegate parent = this.delegate; this.delegate = createDelegate(this.readerContext, root, parent); + if (this.delegate.isDefaultNamespace(root)) { + String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE); + if (StringUtils.hasText(profileSpec)) { + Assert.state(this.environment != null, "Environment must be set for evaluating profiles"); + String[] specifiedProfiles = StringUtils.tokenizeToStringArray( + profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); + if (!this.environment.acceptsProfiles(specifiedProfiles)) { + return; + } + } + } + preProcessXml(root); parseBeanDefinitions(root, this.delegate); postProcessXml(root);