The @Value Decorator

This article requires knowledge of Properties

Main

The @Value decorator allows you to access properties from your properties.json in a programatic way, this means, by using the @Value decorator, you can interact with your configuration in your components or native classes.

Usage

Syntax:

@Value(propertyKey: string)
  • propertyKey

    • Key reference of your property. If nested, please separate by using dots (.)

Example:

// ./src/main/resources/properties.json

{
    "mandarine": {
        "hello-message": "Bonjour!"
    },
    "customKey": "Here goes my custom value"
}

In the example above we can see how we are using @Value on top of two different class fields: one that is static, and one that is not. Although, it works for both.

In the example above, we can also see how we are using nested properties with the @Value decorator.

Last updated