Conditional Configuration
Conditional by Property
If the property matches the defined value then the configuration is applied.
@Configuration
@ConditionalOnProperty(name = "property.name", matchIfMissing = false, havingValue = "true")
public class ConfigClassArgument
Usage
havingValue
The value required to activate the condition
matchIfMissing
If true, the condition activates when the property is not defined
Conditional by Condition Class
When the condition returns true then the configuration is applied.
@Configuration
@Conditional(ConfigurationCondition.class)
public class ConfigClasspublic class ConfigurationCondition implements Condition
{
@Override
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata)
{
// Code
}
}Conditional by Bean
The bean is loaded only if the referenced bean has been loaded:
The bean is loaded only if the referenced bean has NOT been loaded:
Conditional by Class
The bean is loaded only if the class is in the classpath:
The bean is loaded only if the class is missing from the classpath:
Last updated
Was this helpful?