I have a custom condition class and a Configuration that has a conditional Bean based of my custom condition class(MyCondition). The problem is I need to access another bean from the context to evaluate the condition, however this is failing saying failed to find 1 bean of type "myBean" because "myBean" requires some other config to load first. In total there are 3 separate configs to load, the order didnt matter until I introduced the 3rd configuration class called MyConfiguration. ConfigurationA and ConfigurationB need to have loaded before MyConfiguration loads. The problem is the condition is called before any of the other beans are instantiated, so even though the context call below in MyCondition gets the the bean name "myBean"(myBean is created in ConfigurationB file) it fails as it requires another bean from ConfigurationA.
I have tired multiple combinations of dependsOn, AutoConfigureAfter, but the order is not relevant because Spring inherently trys to load the condition before it instantiates/creates the beans in the defaultBeansMap.
ConfigurationA
ConfigurationB
@Configuration
public class MyConfiguration {
@Bean
@Condition(MyCondition.class)
public MyClass createMyClass() {
return new MyClass()
}
}
public class MyCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getBeanFactory().getBean("myBean").getName().equals("Artem");
}
}
Can conditions only work on properties loaded and not on order of runtime objects(classes) required?