Annotation Interface ConfigValue
Injects a single configuration value into a field or constructor parameter, similar to Spring's
@Value. Honored only on dependency-injection-managed beans (e.g. @Component /
@Bean); it has no effect on fields of @Config or @FolderConfig classes
(those are bound by the config binder, not the DI container).
Two addressing modes are supported:
- String mode —
value()holds"configName:path.to.value"(or just"path.to.value"when exactly one config is registered). - Type-safe mode —
config()names a@Configclass andpath()the path within it. Whenconfig()is set it takes precedence overvalue().
The value is resolved once at injection time and does not refresh on config reload.
For values that must track reloads, inject ConfigRef<T> or the @Config class itself.
If the path resolves to no value and no defaultValue() was supplied, injection fails fast
with a ConfigException naming the path and the injection site.
-
Optional Element Summary
Optional Elements -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSentinel meaning "nodefaultValue()was supplied".
-
Field Details
-
DEFAULT_NONE
Sentinel meaning "nodefaultValue()was supplied". Lets an empty string be a valid explicit default while still distinguishing the unset case. Not intended to be referenced by user code.- See Also:
-
-
Element Details
-
value
String value- Returns:
- the config path, or empty if
config()is used instead
- Default:
- ""
-
defaultValue
String defaultValueDefault value applied (and coerced to the target type) when the path resolves to nothing. Defaults toDEFAULT_NONE, which means "no default" — absence then fails fast.- Returns:
- the default value
- Default:
- "\n\t\t\t @ConfigValue#DEFAULT_NONE \t\t\t\n"
-
config
Class<?> configAlternative tovalue(): reference the@Configclass directly. Takes precedence overvalue()when set to anything other thanVoid.class.- Returns:
- the config class
- Default:
- java.lang.Void.class
-
path
String path- Returns:
- the path
- Default:
- ""
-