Chaithra Shenoy
Chaithra Shenoy

Reputation: 53

how to get Array of values from consul in Springboot

I have multiple host values according to different markets how to fetch all those in spring-boot to create a bean. I have tried with

@value("#{${app.host}}")
private String[] host;

consul values

app:
  host:
    hostone: 'localhost:8080'
    hosttwo: 'abc:8089'

Upvotes: 0

Views: 1010

Answers (1)

Rocco Reali
Rocco Reali

Reputation: 36

You can obtain an array whit the following annotation

@Value("${app.host}")
private String[] host;

but your yml should be

app:
  host:
    - localhost:8080
    - abc:8089

or you can get

@Value("${app.host}")
private Map<String,String> host;

and keep your YML file as-is.

Upvotes: 2

Related Questions