Injecting Configuration

Since 3.2

Overview

The platform provides the ability to initialize @Configured annotated fields and methods with configuration values from the XRuntime. This provides a declarative alternative to using the XRuntime.getValue() API programmatically.

Annotated fields and methods are discovered automatically for the main Talon application class. Additional classes can be exposed using the @AppConfiguredAccessor or @AppIntrospectionPoints annotations.

The @Configured Annotation

The @Configured annotation is used to annotate application fields and methods to allow them to be discovered by the Talon XVM. The Talon XVM will populate these fields and methods with settings from the Talon configuration.

Annotation Elements

Element
Type
Description
Default

property

String (required)

The configuration property name

-

required

boolean

Whether the property is required

false

defaultValue

String

The default value if property not set

<null>

description

String

A description of the property

<null>

Supported Types

Configuration values can be of the following types:

  • boolean

  • byte

  • short

  • int

  • long

  • float

  • double

  • char

  • String or XString

  • enumerations

Using @Configured on Fields

You can annotate fields directly for configuration injection:

Using @Configured on Setter Methods

You can also annotate setter methods for configuration injection:

Configuration Discovery

Main Application Class

Any @Configured annotated field or method in the main application class will be discovered automatically by the Talon XVM. No additional setup is required.

Additional Classes with @AppConfiguredAccessor

If additional classes in your application contain configured fields or methods, they can be exposed to the XVM using the @AppConfiguredAccessor annotation:

Additional Classes with @AppIntrospectionPoints

The @AppIntrospectionPoints annotation exposes a collection of application objects to introspect for any type of annotation supported by Talon, including @Configured. This is a broader annotation that can be used instead of the more narrowly scoped @AppConfiguredAccessor:

Choosing Between Annotations

Use @AppConfiguredAccessor for applications that have a large number of objects to reduce the number of objects that the XVM needs to scan for annotations. Use @AppIntrospectionPoints when you want to expose objects for multiple annotation types (@Configured, @EventHandler, @AppStat, @Command, etc.) to reduce boilerplate code.

Limitations

In order to avoid potential race conditions with static fields and preserve the semantics of the "final" keyword, the @Configured annotation does not support injecting properties into fields that are declared static or final.

If you attempt to annotate a static or final field with @Configured, the framework will throw a CliException at initialization time.

Programmatic Access to Configuration

Configuration settings remain accessible via the XRuntime.getValue() API even when using annotation-driven configuration:

Lifecycle Integration

Configuration injection occurs during the microservice lifecycle after the engine descriptor is prepared. The sequence is:

  1. Talon XVM loads the microservice main class

  2. XVM injects the application loader

  3. XVM prepares the engine descriptor

  4. XVM calls @AppConfiguredAccessor (if present)

  5. XVM performs configuration injection on discovered objects

  6. XVM continues with remainder of lifecycle (command handlers, event handlers, etc.)

See Lifecycle for complete lifecycle details.

See Also

Last updated