Annotation Interface ConditionalOnTestProperty


@Retention(RUNTIME) @Target({TYPE,METHOD}) @Conditional(OnTestPropertyCondition.class) public @interface ConditionalOnTestProperty
ConditionalOnTestProperty is a custom conditional annotation for Spring that enables or disables beans based on the presence and value of a specific environment property, typically used in test scenarios.

This annotation can be applied to configuration classes or bean methods. It checks if the environment contains a property with the specified key and if its value matches the provided value. The condition can be negated using the negated property.

Properties:

  • key: The name of the environment property to check.
  • value: The expected value of the property for the condition to match.
  • negated: If true, the condition matches when the property value does not equal the expected value. Default is false.

Note: If either key or value is null, the condition will always return false.

  • Element Details

    • key

      String key
    • value

      String value
    • negated

      boolean negated
      Default:
      false