Annotation Type ConditionalOnExpression


@Retention(CLASS) @Target({TYPE,METHOD}) public @interface ConditionalOnExpression

Constructs this bean only when a boolean expression over the configuration is true. Evaluated once at start-up, like ConditionalOnProperty.

Spring evaluates SpEL here. This is the part of it a condition is written in, and nothing else -- no method calls, no bean references, no arithmetic:

  • ${key} and ${key:default}, replaced by the configuration value (an unset key with no default is the empty string);
  • literals: true, false, and text in single quotes;
  • == and !=, comparing text exactly;
  • ! or not, && or and, || or or, and parentheses.

A bare value is true when it reads true, ignoring case, so "${feature.enabled:false}" works on its own. Anything outside this subset stops the server at start-up, naming the expression.

@ConditionalOnExpression("${billing.provider:none} == 'paddle' && !${billing.sandbox:false}")
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The expression; Spring's default is "true".
  • Element Details

    • value

      String value
      The expression; Spring's default is "true".
      Default:
      "true"