how to load two dimensional integer array from application.properties file into a java class

Viewed 20

I want to add this to application.properties file
my.list.of.strings={{1,2},{2,3}}
And load this value into Java class. How do I do this?
I have tried
@Value("#{'${my.list.of.strings}'.split(',')}")
private List myList;
but it didnot work...

1 Answers

I solved it a year ago by creating a config class.

Config yaml:

my:
  servers:
    - dev.example.com
    - another.example.com

Config class:

@Profile("servers")
@Component
@ConfigurationProperties(prefix = "my")
@NoArgsConstructor
@AllArgsConstructor
public class PackageConfig {

    private List<String> servers = new ArrayList();

    public List<String> getServers() {
        return this.servers;
    }

    public void setServers(List<String> servers) {
        this.servers = servers;
    }
}
Related