I need to check that two conditions are satisfied on a YAML property file, while creating a bean. How do I do that, as the @ConditionalOnProperty annotation supports only one property?
I need to check that two conditions are satisfied on a YAML property file, while creating a bean. How do I do that, as the @ConditionalOnProperty annotation supports only one property?
Use @ConditionalOnExpression annotation and SpEL expression as described here http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html.
Example:
@Controller
@ConditionalOnExpression("${controller.enabled} and ${some.value} > 10")
public class WebController {
@ConditionalOnExpression("#{${path.to.property.one:true} and ${path.to.property.two:true}}")
both true values are the default value if property is not found.