79635502

Date: 2025-05-23 12:31:39
Score: 0.5
Natty:
Report link

If you want all properties to have the same value:

@ConditionalOnProperty(value = {"random.property.one", "random.property.two"}, havingValue = "true", matchIfMissing = false)
@Bean
public ConditionalyCreatedBean conditionallyCreateadBean() {
    return new ConditionalyCreatedBean();
}

Maybe more flexible:

@ConditionalOnExpression("#{${random.property.one} and ${random.property.two}")

Note: Compile-time vs Runtime Evaluation

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @ConditionalOnProperty
  • User mentioned (0): @ConditionalOnExpression
  • Low reputation (0.5):
Posted by: Dimitrije Glisic