Currently @ConditionalOnBean is limited to only inspecting the beans registering thus far in the configuration. If the required bean is registered later during configuration, the conditional bean will not be created, leading to missing beans.

I propose a deferred re-evaluation of beans that don't pass this condition, to be rechecked after the configuration finishes.

An example, using a simple but inefficient brute force procedure:

        boolean resolved;
        do {
            resolved = false;
            for (var it = failedConditionalBeans.iterator(); it.hasNext(); ) {
                Object bean = it.next();
                boolean resolvedThis = tryToResolveAgain( bean );
                if (resolvedThis ) it.remove();
                resolved |= resolvedThis;
            }
        } while (resolved);

Or using an optimized procedure by building a dependency graph.

Affects: https://github.com/spring-projects/spring-boot/issues/26431, etc...

Comment From: wilkinsona

Thanks for the suggestion, but this would introduce a level of complexity that we're not comfortable with. As @snicoll already explain, bean-based conditions should be used on auto-configuration classes which are already guaranteed to be processed after normal user configuration. If you have interdependencies between auto-configuration classes they should be ordered using @AutoConfigureBefore and @AutoConfigureAfter.