com.typesafe.config.Config.resolveWith()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(283)

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

Config.resolveWith介绍

[英]Like Config#resolve() except that substitution values are looked up in the given source, rather than in this instance. This is a special-purpose method which doesn't make sense to use in most cases; it's only needed if you're constructing some sort of app-specific custom approach to configuration. The more usual approach if you have a source of substitution values would be to merge that source into your config stack using Config#withFallback and then resolve.

Note that this method does NOT look in this instance for substitution values. If you want to do that, you could either merge this instance into your value source using Config#withFallback, or you could resolve multiple times with multiple sources (using ConfigResolveOptions#setAllowUnresolved(boolean) so the partial resolves don't fail).
[中]与Config#resolve()类似,只是在给定源中查找替换值,而不是在本实例中。这是一种特殊用途的方法,在大多数情况下使用没有意义;只有在构建某种特定于应用程序的自定义配置方法时才需要它。如果您有一个替换值的源,则更常用的方法是使用config#with fallback将该源合并到配置堆栈中,然后解析。
请注意,此方法不会在此实例中查找替换值。如果要这样做,您可以使用Config#with fallback将此实例合并到您的值源中,或者可以使用多个源多次解析(使用ConfigResolveOptions#setAllowUnresolved(布尔值),以便部分解析不会失败)。

代码示例

代码示例来源:origin: apache/incubator-gobblin

if(!StringUtils.isEmpty(resourceKey)) {
 final String dummyKey = "DUMMY";
 Config tmpConfig = ConfigFactory.parseString(dummyKey + "=" + resourceKey).resolveWith(srcConfig);
 resourceKey = tmpConfig.getString(dummyKey);
Config destConfig = ConfigFactory.parseString(hoconInput).resolveWith(srcConfig);
JsonObject json = parser.parse(destConfig.root().render(ConfigRenderOptions.concise())).getAsJsonObject();
return new SingleRecordIterable<>(new RestEntry<>(resourceKey, json));

代码示例来源:origin: dswarm/dswarm

private static Config mergedConfig(final Config defaultConf, final Config unresolvedConf) {
  return unresolvedConf
      .resolveWith(defaultConf)
      .withFallback(defaultConf);
}

代码示例来源:origin: ashwanthkumar/gocd-slack-build-notifier

protected Rules load(Config config) {
  Config envThenSystem = ConfigFactory.systemEnvironment().withFallback(ConfigFactory.systemProperties());
  Config configWithFallback = config.withFallback(ConfigFactory.load(getClass().getClassLoader())).resolveWith(envThenSystem);
  return Rules.fromConfig(configWithFallback.getConfig("gocd.slack"));
}

代码示例来源:origin: addthis/hydra

.resolveWith(pluginRegistry.config());
ConfigValue expandedConfig = Configs.expandSugar(TaskRunnable.class, jobConfig.root(), pluginRegistry);
switch (normalizedFormat) {

代码示例来源:origin: org.apache.gobblin/gobblin-core

if(!StringUtils.isEmpty(resourceKey)) {
 final String dummyKey = "DUMMY";
 Config tmpConfig = ConfigFactory.parseString(dummyKey + "=" + resourceKey).resolveWith(srcConfig);
 resourceKey = tmpConfig.getString(dummyKey);
Config destConfig = ConfigFactory.parseString(hoconInput).resolveWith(srcConfig);
JsonObject json = parser.parse(destConfig.root().render(ConfigRenderOptions.concise())).getAsJsonObject();
return new SingleRecordIterable<>(new RestEntry<>(resourceKey, json));

代码示例来源:origin: addthis/hydra

.withFallback(defaultGlobalDefaults)
                 .resolve();
  jobConfig = jobConfig.resolveWith(globalDefaults);
  codec = defaultCodec.withConfig(globalDefaults);
} else {
  jobConfig = jobConfig.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
             .resolveWith(defaultGlobalDefaults);
  codec = defaultCodec;

代码示例来源:origin: cloudera-labs/envelope

@Test
public void testFindReplaceStringValues() {
 Config baseConfig = ConfigFactory.parseString("a: ${replaceme}, b: \"${replaceme}\", c: [${replaceme}, ${replaceme}], d: [\"${replaceme}\", \"${replaceme}\"], e: { f: \"${replaceme}\", g: [\"${replaceme}\"] }" );
 Config resolvedConfig = baseConfig.resolveWith(ConfigFactory.empty().withValue("replaceme", ConfigValueFactory.fromAnyRef("REPLACED")));
 Config replacedConfig = ConfigUtils.findReplaceStringValues(resolvedConfig, "\\$\\{replaceme\\}", "REPLACED");

 assertEquals(replacedConfig.getString("a"), "REPLACED");
 assertEquals(replacedConfig.getString("b"), "REPLACED");
 assertEquals(replacedConfig.getStringList("c").get(0), "REPLACED");
 assertEquals(replacedConfig.getStringList("c").get(1), "REPLACED");
 assertEquals(replacedConfig.getStringList("d").get(0), "REPLACED");
 assertEquals(replacedConfig.getStringList("d").get(1), "REPLACED");
 assertEquals(replacedConfig.getConfig("e").getString("f"), "REPLACED");
 assertEquals(replacedConfig.getConfig("e").getStringList("g").get(0), "REPLACED");
}

代码示例来源:origin: addthis/hydra

.withFallback(defaultGlobalDefaults)
                 .resolve();
  jobConfig = jobConfig.resolveWith(globalDefaults);
  codec = defaultCodec.withConfig(globalDefaults);
} else {
  jobConfig = jobConfig.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true))
             .resolveWith(defaultGlobalDefaults);
  codec = defaultCodec;

相关文章