Description
Dave Syer opened SPR-16959 and commented
There is a gap in the the functional bean registration features in BeanDefinitionBuilder
and GenericApplicationContext
. Once you register a Supplier
you have committed to provide an instance of the class you register, whereas in a lot of use cases you don't know whether or not you want to provide it until the bean factory is available (e.g. conditional on another instance of the same class being available). I guess the change needs to be in the BeanDefinitionRegistry
interface, for example to support a Predicate<ConditionContext>
as well as the Supplier
. If the interface doesn't change, I suppose returning null
from the Supplier
might be an option, but that seems a bit ugly, and might be too late, since the BeanDefinition
has already been registered at that point.
Issue Links:
- Programmatic bean registration with configuration classes #18353 Programmatic bean registration within configuration classes