我有一些创建ConfigurationProviderBuilder的java代码。
private static ExampleConf conf(String confFile) {
ConfigFilesProvider configFilesProvider =
() -> Arrays.asList(Paths.get(confFile).toAbsolutePath());
// use local files as config source
ConfigurationSource source =
new FilesConfigurationSource(configFilesProvider);
// create provider
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.build()
.bind("", ExampleConf.class);
}
ExampleConf看起来像这样
public interface ExampleConf {
String host();
int port();
String certFile();
}
最后,实际的配置文件看起来像这样
host: localhost
port: 8980
certFile: /usr2/certs/ca/ca.crt
这很容易,但现在我想在yaml配置文件中创建一个嵌套结构。像这样的东西
paths:
- name: path one
columns:
- foo
- bar
- name: path two
columns:
- mario
- luigi
如何将此^转换为java代码,以便在ExampleConf中使用?
我还在快速掌握java,这对我来说在python中会更容易。
答案 0 :(得分:1)
尝试:
public interface ExampleConf {
public interface MyObject {
String name();
List<String> columns();
}
List<MyObject> paths();
}