@Import detects and accepts existing configuration class in any order of processing

This commit is contained in:
Juergen Hoeller
2009-05-13 20:49:45 +00:00
parent 1ded650a6c
commit 14732c5dc2
4 changed files with 49 additions and 23 deletions

View File

@@ -34,9 +34,7 @@ import org.springframework.util.ClassUtils;
/**
* Represents a user-defined {@link Configuration @Configuration} class.
* Includes a set of {@link Bean} methods, including all such methods defined in the
* ancestry of the class, in a 'flattened-out' manner. Note that each {@link ConfigurationClassMethod}
* representation contains source information about where it was originally detected
* (for the purpose of tooling with Spring IDE).
* ancestry of the class, in a 'flattened-out' manner.
*
* @author Chris Beams
* @author Juergen Hoeller
@@ -131,14 +129,8 @@ final class ConfigurationClass {
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ConfigurationClass)) {
return false;
}
ConfigurationClass otherCc = (ConfigurationClass) other;
return getMetadata().getClassName().equals(otherCc.getMetadata().getClassName());
return (this == other || (other instanceof ConfigurationClass &&
getMetadata().getClassName().equals(((ConfigurationClass) other).getMetadata().getClassName())));
}
@Override

View File

@@ -51,6 +51,7 @@ import org.springframework.util.StringUtils;
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.0
* @see ConfigurationClassParser
*/
class ConfigurationClassBeanDefinitionReader {

View File

@@ -37,12 +37,12 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
/**
* Parses a {@link Configuration} class definition, populating a configuration model.
* This ASM-based implementation avoids reflection and eager classloading in order to
* interoperate effectively with tooling (Spring IDE) and OSGi environments.
* This ASM-based implementation avoids reflection and eager class loading in order to
* interoperate effectively with lazy class loading in a Spring ApplicationContext.
*
* <p>This class helps separate the concern of parsing the structure of a Configuration class
* from the concern of registering {@link BeanDefinition} objects based on the content of
* that model.
* <p>This class helps separate the concern of parsing the structure of a Configuration
* class from the concern of registering {@link BeanDefinition} objects based on the
* content of that model.
*
* @author Chris Beams
* @author Juergen Hoeller
@@ -112,7 +112,12 @@ class ConfigurationClassParser {
metadata = null;
}
}
model.add(configClass);
if (this.model.contains(configClass) && configClass.getBeanName() != null) {
// Explicit bean definition found, probably replacing an import.
// Let's remove the old one and go with the new one.
this.model.remove(configClass);
}
this.model.add(configClass);
}
protected void doProcessConfigurationClass(ConfigurationClass configClass, AnnotationMetadata metadata) throws IOException {