> For the complete documentation index, see [llms.txt](https://docs.rumi.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rumi.systems/rumi-core/guides/developing-applications/authoring-user-code/configuration/injecting-configuration.md).

# Injecting Configuration

{% hint style="info" %}
**Since 3.2**
{% endhint %}

## 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

| 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:

```java
import com.neeve.cli.annotations.Configured;

@AppHAPolicy(HAPolicy.EventSourcing)
public class MyApp {

  @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
  private int orderPreallocateCount;

  @Configured(property = "myapp.maxOrderSize", required = true)
  private int maxOrderSize;
}
```

## Using @Configured on Setter Methods

You can also annotate setter methods for configuration injection:

```java
import com.neeve.cli.annotations.Configured;

@AppHAPolicy(HAPolicy.EventSourcing)
public class MyApp {
  private int orderPreallocateCount;

  @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
  void setOrderPreallocateCount(int orderPreallocateCount) {
    this.orderPreallocateCount = orderPreallocateCount;
  }
}
```

## 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:

```java
@AppHAPolicy(HAPolicy.EventSourcing)
public class MyApp {
    MyOtherClass someOtherClass = new MyOtherClass();

    @AppConfiguredAccessor
    public void getConfiguredContainers(Set<Object> containers) {
        containers.add(someOtherClass);
    }
}

private class MyOtherClass {
    @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
    private int orderPreallocateCount;

    MyOtherClass() {
    }
}
```

### 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:

```java
@AppHAPolicy(HAPolicy.EventSourcing)
public class MyApp {
    MyOtherClass someOtherClass = new MyOtherClass();

    @AppIntrospectionPoints
    public void getApplicationObjects(Set<Object> objects) {
        objects.add(someOtherClass);
    }
}

private class MyOtherClass {
    @Configured(property = "simulator.ems.orderPreallocateCount", defaultValue = "1048576")
    private int orderPreallocateCount;

    MyOtherClass() {
    }
}
```

{% hint style="info" %}
**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.
{% endhint %}

## 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:

```java
String value = Config.getValue("my.property.name", "defaultValue");
```

## Lifecycle Integration

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

1. Rumi container loads the microservice main class
2. Container injects the application loader
3. Container prepares the engine descriptor
4. **Container calls @AppConfiguredAccessor (if present)**
5. **Container performs configuration injection on discovered objects**
6. Container continues with remainder of lifecycle (command handlers, event handlers, etc.)

See [Lifecycle](/rumi-core/concepts/microservice-operation/lifecycle.md) for complete lifecycle details.

## See Also

* [Lifecycle](/rumi-core/concepts/microservice-operation/lifecycle.md) - Microservice lifecycle and configuration injection timing
* [Configuration Model](/rumi-core/concepts/microservice-architecture/configuration-model.md) - Understanding Rumi's configuration architecture
* [Implementing Lifecycle Methods](/rumi-core/guides/developing-applications/authoring-user-code/lifecycle/implementing-lifecycle-methods.md) - Other lifecycle injection points
