how to get Array of values from consul in Springboot

836 Views Asked by At

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'
1

There are 1 best solutions below

0
On BEST ANSWER

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.