Annotation Type ConditionalOnProperty


  • @Retention(RUNTIME)
    @Target({TYPE,METHOD})
    @Documented
    @Conditional(org.springframework.boot.autoconfigure.condition.OnPropertyCondition.class)
    public @interface ConditionalOnProperty
    Conditional that checks if the specified properties have a specific value. By default the properties must be present in the Environment and not equal to false. The havingValue() and matchIfMissing() attributes allow further customizations.

    The havingValue() attribute can be used to specify the value that the property should have. The table below shows when a condition matches according to the property value and the havingValue() attribute:

    Property ValuehavingValue=""havingValue="true"havingValue="false"havingValue="foo"
    "true"yesyesnono
    "false"nonoyesno
    "foo"yesnonoyes

    If the property is not contained in the Environment at all, the matchIfMissing() attribute is consulted. By default missing attributes do not match.

    Since:
    1.1.0
    • Optional Element Summary

      Optional Elements 
      Modifier and TypeOptional ElementDescription
      StringhavingValue
      The string representation of the expected value for the properties.
      booleanmatchIfMissing
      Specify if the condition should match if the property is not set.
      String[]name
      The name of the properties to test.
      Stringprefix
      A prefix that should be applied to each property.
      booleanrelaxedNames
      If relaxed names should be checked.
      String[]value
      Alias for name().
      • prefix

        String prefix
        A prefix that should be applied to each property. The prefix automatically ends with a dot if not specified.
        Returns:
        the prefix
        Default:
        ""
      • name

        String[] name
        The name of the properties to test. If a prefix has been defined, it is applied to compute the full key of each property. For instance if the prefix is app.config and one value is my-value, the fully key would be app.config.my-value

        Use the dashed notation to specify each property, that is all lower case with a "-" to separate words (e.g. my-long-property).

        Returns:
        the names
        Default:
        {}
      • havingValue

        String havingValue
        The string representation of the expected value for the properties. If not specified, the property must not be equals to false.
        Returns:
        the expected value
        Default:
        ""
      • matchIfMissing

        boolean matchIfMissing
        Specify if the condition should match if the property is not set. Defaults to false.
        Returns:
        if should match if the property is missing
        Default:
        false
      • relaxedNames

        boolean relaxedNames
        If relaxed names should be checked. Defaults to true.
        Returns:
        if relaxed names are used
        Default:
        true