Injecting Configuration
Since 3.2
Overview
The platform provides the ability to initialize @Configured annotated fields and methods with configuration values from the global environment. This provides a declarative alternative to using the Config.getValue() API programmatically.
Annotated fields and methods are discovered automatically for the main Rumi 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 Rumi container. The Rumi container will populate these fields and methods with settings from the Rumi 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 Rumi container. 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 container 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 Rumi, 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 container 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 Config.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:
Rumi container loads the microservice main class
Container injects the application loader
Container prepares the engine descriptor
Container calls @AppConfiguredAccessor (if present)
Container performs configuration injection on discovered objects
Container 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 Rumi's configuration architecture
Implementing Lifecycle Methods - Other lifecycle injection points
Last updated

