Annotation Interface ConditionalOnSingleCandidate
@Conditional
that only matches when a bean of the specified class
is already contained in the BeanFactory
and a single candidate can be
determined.
The condition will also match if multiple matching bean instances are already contained
in the BeanFactory
but a primary candidate has been defined; essentially, the
condition match if auto-wiring a bean with the defined type will succeed.
The condition can only match the bean definitions that have been processed by the application context so far and, as such, it is strongly recommended to use this condition on auto-configuration classes only. If a candidate bean may be created by another auto-configuration, make sure that the one using this condition runs after.
- Since:
- 1.3.0
- Author:
- Stephane Nicoll
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
Class<?> valueThe class type of bean that should be checked. The condition matches if a bean of the class specified is contained in theBeanFactory
and a primary candidate exists in case of multiple instances. Beans that are not autowire candidates or that are not default candidates are ignored.This attribute may not be used in conjunction with
type()
, but it may be used instead oftype()
.- Returns:
- the class type of the bean to check
- See Also:
- Default:
- java.lang.Object.class
-
type
String typeThe class type name of bean that should be checked. The condition matches if a bean of the class specified is contained in theBeanFactory
and a primary candidate exists in case of multiple instances. Beans that are not autowire candidates or that are not default candidates are ignored.This attribute may not be used in conjunction with
value()
, but it may be used instead ofvalue()
.- Returns:
- the class type name of the bean to check
- See Also:
- Default:
- ""
-
search
SearchStrategy searchStrategy to decide if the application context hierarchy (parent contexts) should be considered.- Returns:
- the search strategy
- Default:
- ALL
-