Apply initializers and bean registrations before registering classes

Previously, classes were registered first which meant that their
conditions were evaluated before any initializers and bean
registrations were applied. This prevented the bean registrations and
initializers from affecting the outcome of the condition evaluation.

This commit inverts the ordering so that classes are not registerd,
and therefore their conditions are not evaluated, until after the
bean registrations and initializers have been applied.

Closes gh-31280
This commit is contained in:
Andy Wilkinson
2022-06-08 18:43:32 +01:00
parent e30391ca7a
commit 62f40f2c38
2 changed files with 17 additions and 3 deletions

View File

@@ -402,12 +402,12 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
((DefaultResourceLoader) context).setClassLoader(this.runnerConfiguration.classLoader);
}
this.runnerConfiguration.environmentProperties.applyTo(context);
this.runnerConfiguration.beanRegistrations.forEach((registration) -> registration.apply(context));
this.runnerConfiguration.initializers.forEach((initializer) -> initializer.initialize(context));
Class<?>[] classes = Configurations.getClasses(this.runnerConfiguration.configurations);
if (classes.length > 0) {
((AnnotationConfigRegistry) context).register(classes);
}
this.runnerConfiguration.beanRegistrations.forEach((registration) -> registration.apply(context));
this.runnerConfiguration.initializers.forEach((initializer) -> initializer.initialize(context));
context.refresh();
}