ConditionalOnProperty class
Marks a class or method as conditional based on the presence and value of configuration properties.
This annotation is used to include or exclude a class based on one or more environment or system properties. It is commonly used in auto-configuration or module activation scenarios.
Matching Rules
- You can specify multiple names via
names
. - If
havingValue
is specified, the property must match that value. - If
havingValue
is omitted, the property must not be equal to'false'
. - If the property is missing and
matchIfMissing
istrue
, it will match.
Example
@ConditionalOnProperty(
prefix: 'server',
names: ['ssl.enabled', 'ssl.enabled2'],
havingValue: 'true',
)
class SslServerConfig {}
This activates SslServerConfig
only if server.ssl.enabled=true
.
- Annotations
-
- @Conditional([ClassType<OnPropertyCondition>()])
- @Target.new({TargetKind.classType, TargetKind.method})
Constructors
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- havingValue → String?
-
The expected value the property must equal for the condition to match.
final
- matchIfMissing → bool
-
Whether to match even if the property is not set.
final
-
names
→ List<
String> -
Alternative to
name
; defines multiple property names to match.final - prefix → String?
-
Optional prefix to prepend to the property name(s).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode
, andtoString
. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited