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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user