org.springframework.core.env.PropertySource.toString()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(123)

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

PropertySource.toString介绍

[英]Produce concise output (type and name) if the current log level does not include debug. If debug is enabled, produce verbose output including the hash code of the PropertySource instance and every name/value property pair.

This variable verbosity is useful as a property source such as system properties or environment variables may contain an arbitrary number of property pairs, potentially leading to difficult to read exception and log messages.
[中]如果当前日志级别不包括调试,则生成简洁的输出(类型和名称)。如果启用了调试,则生成详细的输出,包括PropertySource实例和每个名称/值属性对的哈希代码。
此变量详细性非常有用,因为系统属性或环境变量等属性源可能包含任意数量的属性对,这可能会导致难以读取异常和日志消息。

代码示例

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public String toString() {
  return this.propertySource.toString();
}

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public String toString() {
  return this.propertySource.toString();
}

代码示例来源:origin: spring-cloud/spring-cloud-config

@Override
protected void doHealthCheck(Builder builder) throws Exception {
  PropertySource<?> propertySource = getPropertySource();
  builder.up();
  if (propertySource instanceof CompositePropertySource) {
    List<String> sources = new ArrayList<>();
    for (PropertySource<?> ps : ((CompositePropertySource) propertySource).getPropertySources()) {
      sources.add(ps.getName());
    }
    builder.withDetail("propertySources", sources);
  } else if (propertySource!=null) {
    builder.withDetail("propertySources", propertySource.toString());
  } else {
    builder.unknown().withDetail("error", "no property sources located");
  }
}

代码示例来源:origin: theotherp/nzbhydra2

@Secured({"ROLE_ADMIN"})
@RequestMapping(value = "/internalapi/config", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ConfigValidationResult setConfig(@RequestBody BaseConfig newConfig) throws IOException {
  for (PropertySource<?> source : environment.getPropertySources()) {
    Set propertyNames = new HashSet();
    if (source.getSource() instanceof Properties) {
      propertyNames = ((Properties) source.getSource()).stringPropertyNames();
    } else if (source.getSource() instanceof LinkedHashMap) {
      propertyNames = ((LinkedHashMap) source.getSource()).keySet();
    }
    boolean contains = propertyNames.contains("main.externalUrl");
    if (contains) {
      logger.info(source.toString());
    }
  }
  logger.info("Received new config");
  newConfig = newConfig.prepareForSaving();
  ConfigValidationResult result = newConfig.validateConfig(configProvider.getBaseConfig(), newConfig);
  if (result.isOk()) {
    configProvider.getBaseConfig().replace(newConfig);
    configProvider.getBaseConfig().save();
    result.setNewConfig(configProvider.getBaseConfig());
  }
  return result;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-config-client

@Override
protected void doHealthCheck(Builder builder) throws Exception {
  PropertySource<?> propertySource = getPropertySource();
  builder.up();
  if (propertySource instanceof CompositePropertySource) {
    List<String> sources = new ArrayList<>();
    for (PropertySource<?> ps : ((CompositePropertySource) propertySource).getPropertySources()) {
      sources.add(ps.getName());
    }
    builder.withDetail("propertySources", sources);
  } else if (propertySource!=null) {
    builder.withDetail("propertySources", propertySource.toString());
  } else {
    builder.unknown().withDetail("error", "no property sources located");
  }
}

相关文章