如何将二维整数数组从Applation.Properties文件加载到Java类中

wvt8vs2t  于 2022-09-18  发布在  Java
关注(0)|答案(1)|浏览(182)

我想将其添加到Applation.Properties文件中
My.list.of.string={{1,2},{2,3}}
并将该值加载到Java类中。我该怎么做呢?
我试过了
@VALUE(“#{‘${my.list.of.string}’.Split(‘,’)}”)
个人分发名单myList;
但它并没有起作用。

ewm0tg9j

ewm0tg9j1#

一年前,我通过创建一个配置类解决了这个问题。

配置YAML:

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

配置类:

@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;
    }
}

相关问题