Prevent incorrect ImportAware metdata injection

Update ImportRegistry to track all import registrations that occur
against an importing class (rather than just keeping the last). In
addition, prune imported classes from the registry when a configuration
class is removed during the REGISTER_BEAN ConfigurationPhase.

This update prevents incorrect metadata from being injected into an
ImportAware class which is imported twice by different configurations
classes (when one of the configuration classes will be ultimately skipped
due to a @Condition).

Issue: SPR-12128
This commit is contained in:
Phillip Webb
2014-09-02 20:33:46 -07:00
parent 8bf141eca9
commit abc343f407
4 changed files with 33 additions and 12 deletions

View File

@@ -234,7 +234,7 @@ public class ImportAwareTests {
}
@Conditional(NeverMatchingCondition.class)
@Conditional(OnMissingBeanCondition.class)
@EnableSomeConfiguration("foo")
@Configuration
public static class ConfigurationTwo {
@@ -277,11 +277,12 @@ public class ImportAwareTests {
}
private static final class NeverMatchingCondition implements ConfigurationCondition {
private static final class OnMissingBeanCondition implements ConfigurationCondition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return false;
return context.getBeanFactory().getBeanNamesForType(MetadataHolder.class,
true, false).length == 0;
}
@Override