@Target(value={TYPE,METHOD}) @Retention(value=RUNTIME) @Documented @Conditional(value=org.springframework.boot.autoconfigure.condition.OnBeanCondition.class) public @interface ConditionalOnMissingBean
Conditional
that only matches when no beans meeting the specified requirements
are already contained in the BeanFactory
. None of the requirements must be met
for the condition to match and the requirements do not have to be met by the same bean.
When placed on a @Bean
method, the bean class defaults to the return type of
the factory method:
@Configuration public class MyAutoConfiguration { @ConditionalOnMissingBean @Bean public MyService myService() { ... } }
In the sample above the condition will match if no bean of type MyService
is
already contained in the BeanFactory
.
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.
Modifier and Type | Optional Element and Description |
---|---|
Class<? extends Annotation>[] |
annotation
The annotation type decorating a bean that should be checked.
|
Class<?>[] |
ignored
The class types of beans that should be ignored when identifying matching beans.
|
String[] |
ignoredType
The class type names of beans that should be ignored when identifying matching
beans.
|
String[] |
name
The names of beans to check.
|
Class<?>[] |
parameterizedContainer
Additional classes that may contain the specified bean types within their generic
parameters.
|
SearchStrategy |
search
Strategy to decide if the application context hierarchy (parent contexts) should be
considered.
|
String[] |
type
The class type names of beans that should be checked.
|
Class<?>[] |
value
The class types of beans that should be checked.
|
public abstract Class<?>[] value
BeanFactory
.public abstract String[] type
BeanFactory
.public abstract Class<?>[] ignored
public abstract String[] ignoredType
public abstract Class<? extends Annotation>[] annotation
BeanFactory
.public abstract String[] name
BeanFactory
.public abstract SearchStrategy search
public abstract Class<?>[] parameterizedContainer
value=Name.class
and
parameterizedContainer=NameRegistration.class
would detect both
Name
and NameRegistration<Name>
.Copyright © 2020 Pivotal Software, Inc.. All rights reserved.