ObjectFactory designed specifically for injection points,
allowing for programmatic optionality and lenient not-unique handling.
As of 5.1, this interface extends Iterable and provides Stream
support. It can be therefore be used in for loops, provides forEach
iteration and allows for collection-style stream access.
BeanFactory#getBeanProvider, org.springframework.beans.factory.annotation.Autowired
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: an instance of the bean, ornull if not availableReturn an instance (possibly shared or independent) of the object managed by this factory. |
| public default T | Returns: an instance of the bean, or the supplied default object if no such bean is availablea callback for supplying a default object
if none is present in the factory defaultSupplier)Return an instance (possibly shared or independent) of the object managed by this factory. |
| public T | Returns: an instance of the bean, ornull if not available or
not unique (i.e. multiple candidates found with none marked as primary)Return an instance (possibly shared or independent) of the object managed by this factory. |
| public default T | Returns: an instance of the bean, or the supplied default object if no such bean is available or if it is not unique in the factory (i.e. multiple candidates found with none marked as primary)a callback for supplying a default object
if no unique candidate is present in the factory defaultSupplier)Return an instance (possibly shared or independent) of the object managed by this factory. |
| public T | |
| public default void | ifAvailable(Consumer<T>
a callback for processing the target object
if available (not called otherwise) dependencyConsumer)Consume an instance (possibly shared or independent) of the object managed by this factory, if available. |
| public default void | |
| public default Iterator | iterator()
Implements java. Iterator over all matching object instances,
without specific ordering guarantees (but typically in registration order).
|
| public default Stream | orderedStream()
Return a sequential |
| public default Stream |
| getIfAvailable | back to summary |
|---|---|
| public T getIfAvailable() throws BeansException Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| getIfAvailable | back to summary |
|---|---|
| public default T getIfAvailable(Supplier<T> defaultSupplier) throws BeansException Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| getIfUnique | back to summary |
|---|---|
| public T getIfUnique() throws BeansException Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| getIfUnique | back to summary |
|---|---|
| public default T getIfUnique(Supplier<T> defaultSupplier) throws BeansException Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| getObject | back to summary |
|---|---|
| public T getObject(Object... args) throws BeansException Return an instance (possibly shared or independent) of the object managed by this factory. Allows for specifying explicit construction arguments, along the
lines of
| |
| ifAvailable | back to summary |
|---|---|
| public default void ifAvailable(Consumer<T> dependencyConsumer) throws BeansException Consume an instance (possibly shared or independent) of the object managed by this factory, if available.
| |
| ifUnique | back to summary |
|---|---|
| public default void ifUnique(Consumer<T> dependencyConsumer) throws BeansException Consume an instance (possibly shared or independent) of the object managed by this factory, if unique.
| |
| iterator | back to summary |
|---|---|
| public default Iterator Implements java. Return an
| |
| orderedStream | back to summary |
|---|---|
| public default Stream Return a sequential In a standard Spring application context, this will be ordered
according to
| |
| stream | back to summary |
|---|---|
| public default Stream Return a sequential
| |