Annotation Interface ConfigValue


@Retention(RUNTIME) @Target({FIELD,PARAMETER}) public @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 modevalue() holds "configName:path.to.value" (or just "path.to.value" when exactly one config is registered).
  • Type-safe modeconfig() names a @Config class and path() the path within it. When config() is set it takes precedence over value().

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
    Modifier and Type
    Optional Element
    Description
    Alternative to value(): reference the @Config class directly.
    Default value applied (and coerced to the target type) when the path resolves to nothing.
    Path within the config() class.
    Config path in "configName:path" or bare "path" form.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Sentinel meaning "no defaultValue() was supplied".
  • Field Details

    • DEFAULT_NONE

      static final String DEFAULT_NONE
      Sentinel meaning "no defaultValue() 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
      Config path in "configName:path" or bare "path" form. Ignored when config() is set.
      Returns:
      the config path, or empty if config() is used instead
      Default:
      ""
    • defaultValue

      String defaultValue
      Default value applied (and coerced to the target type) when the path resolves to nothing. Defaults to DEFAULT_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<?> config
      Alternative to value(): reference the @Config class directly. Takes precedence over value() when set to anything other than Void.class.
      Returns:
      the config class
      Default:
      java.lang.Void.class
    • path

      String path
      Path within the config() class. Required when config() is set.
      Returns:
      the path
      Default:
      ""