gpt4 book ai didi

com.mesosphere.sdk.config.YAMLConfigurationLoader类的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 15:30:31 28 4
gpt4 key购买 nike

本文整理了Java中com.mesosphere.sdk.config.YAMLConfigurationLoader类的一些代码示例,展示了YAMLConfigurationLoader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YAMLConfigurationLoader类的具体详情如下:
包路径:com.mesosphere.sdk.config.YAMLConfigurationLoader
类名称:YAMLConfigurationLoader

YAMLConfigurationLoader介绍

[英]Utility class that helps load YAML configuration into a POJO, while ensuring that environment variables can override pre-configured configuration values.
[中]

代码示例

代码示例来源:origin: mesosphere/dcos-commons

public static <T> T loadConfigFromEnv(Class<T> configurationClass, final String path)
  throws IOException
{
 LOGGER.info("Parsing configuration file from {} ", path);
 logProcessEnv();
 final Path configPath = Paths.get(path);
 final File file = configPath.toAbsolutePath().toFile();
 final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
 final StrSubstitutor sub = new StrSubstitutor(new StrLookup<Object>() {
  @Override
  public String lookup(String key) {
   return System.getenv(key);
  }
 });
 sub.setEnableSubstitutionInVariables(true);
 final String conf = sub.replace(FileUtils.readFileToString(file));
 return mapper.readValue(conf, configurationClass);
}

代码示例来源:origin: mesosphere/dcos-commons

@Test
  public void testLoader() throws Exception {
    final TestConfig testConfig = YAMLConfigurationLoader.loadConfigFromEnv(TestConfig.class
        , Paths.get(this.getClass().getClassLoader().getResource("test.yml").toURI()).toString());

    Assert.assertEquals("DCOS", testConfig.getName());
    Assert.assertEquals(1, testConfig.getCount());
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com