Injecting Configuration
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
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:
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:
Talon XVM loads the microservice main class
XVM injects the application loader
XVM prepares the engine descriptor
XVM calls @AppConfiguredAccessor (if present)
XVM performs configuration injection on discovered objects
XVM continues with remainder of lifecycle (command handlers, event handlers, etc.)
See Lifecycle for complete lifecycle details.
See Also
Lifecycle - Microservice lifecycle and configuration injection timing
Configuration Model - Understanding Talon's configuration architecture
Implementing Lifecycle Methods - Other lifecycle injection points
Last updated

