Stefan Feuerhahn
Stefan Feuerhahn

Reputation: 1804

How do I read Micronaut array properties from the root of the configuration hierarchy?

If I have a config file

app:
    integers:
        - 1
        - 2

I can use Micronaut's ConfigurationProperties to create config beans:

@ConfigurationProperties("app")
public class AppConfig {
  public List<Integer> integers;
}

But what if the integers array is in the root of the config hierarchy:

integers:
    - 1
    - 2

The following does not seem to work:

@ConfigurationProperties("")
public class RootConfig {
  public List<Integer> integers;
}

Upvotes: 0

Views: 1046

Answers (1)

pvpkiran
pvpkiran

Reputation: 27048

@ConfigurationProperties only works with a prefix. And "" is not a valid prefix.

Moreover @ConfigurationProperties makes sense only if you have many fields(May be that is why it was not designed to work) not for one field like

integers:
    - 1
    - 2

In this case @ConfigurationProperties is a overkill. Just use @Value like this

@Value("${integers}")
public List<Integer> integers;

and declare it like this in yaml

integers: 1,2

Upvotes: 1

Related Questions