io.micronaut.context.env.Environment.getProperty()方法的使用及代码示例

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

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

Environment.getProperty介绍

[英]Obtains the PropertySourceLoader instances.
[中]获取PropertySourceLoader实例。

代码示例

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * Resolves the function name to execution for the environment.
 *
 * @param env The environment
 * @return The function name
 */
protected String resolveFunctionName(Environment env) {
  return env.getProperty(LocalFunctionRegistry.FUNCTION_NAME, String.class, (String) null);
}

代码示例来源:origin: micronaut-projects/micronaut-core

if (result instanceof Writable) {
  Writable writable = (Writable) result;
  writable.writeTo(output, environment.getProperty(LocalFunctionRegistry.FUNCTION_CHARSET, Charset.class, StandardCharsets.UTF_8));
} else {
  Optional<MediaTypeCodec> codec = registry instanceof MediaTypeCodecRegistry ? ((MediaTypeCodecRegistry) registry).findCodec(MediaType.APPLICATION_JSON_TYPE) : Optional.empty();

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public String getRequiredProperty(@Nonnull String key) throws IllegalStateException {
  Assert.notNull(key, "Key must not be null");
  return environment.getProperty(key, String.class).orElseThrow(() -> new IllegalStateException("Property with key [" +key + "] not present"));
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public @Nullable String getProperty(@Nonnull String key) {
  Assert.notNull(key, "Key must not be null");
  return environment.getProperty(key, String.class).orElse(null);
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
  Assert.notNull(key, "Key must not be null");
  Assert.notNull(targetType, "Target type must not be null");
  return environment.getProperty(key, targetType).orElseThrow(() -> new IllegalStateException("Property with key [" +key + "] not present"));
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public @Nonnull String getProperty(@Nonnull String key, @Nonnull String defaultValue) {
  Assert.notNull(key, "Key must not be null");
  return environment.getProperty(key, String.class).orElse(defaultValue);
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public @Nullable <T> T getProperty(@Nonnull String key, @Nonnull Class<T> targetType) {
  Assert.notNull(key, "Key must not be null");
  Assert.notNull(targetType, "Target type must not be null");
  return environment.getProperty(key, targetType).orElse(null);
}

代码示例来源:origin: micronaut-projects/micronaut-spring

@Override
public <T> T getProperty(@Nonnull String key, @Nonnull Class<T> targetType, @Nonnull T defaultValue) {
  Assert.notNull(key, "Key must not be null");
  Assert.notNull(targetType, "Target type must not be null");
  return environment.getProperty(key, targetType).orElse(defaultValue);
}

代码示例来源:origin: io.micronaut/micronaut-management

private MapPropertySource retrieveConfigurationInfo() {
    return new MapPropertySource(
      "info",
      environment.getProperty("info", Map.class).orElse(Collections.emptyMap())
    );
  }
}

代码示例来源:origin: io.micronaut/micronaut-inject

@Override
public <T> Optional<T> getProperty(String name, ArgumentConversionContext<T> conversionContext) {
  return getEnvironment().getProperty(name, conversionContext);
}

代码示例来源:origin: io.micronaut/inject

@Override
public <T> Optional<T> getProperty(String name, ArgumentConversionContext<T> conversionContext) {
  return getEnvironment().getProperty(name, conversionContext);
}

代码示例来源:origin: io.micronaut/management

private MapPropertySource retrieveConfigurationInfo() {
    return new MapPropertySource(
      "info",
      environment.getProperty("info", Map.class).orElse(Collections.emptyMap())
    );
  }
}

代码示例来源:origin: io.micronaut/runtime

@Nonnull
  @Override
  public String generateId(Environment environment, ServiceInstance serviceInstance) {
    Optional<String> cloudFoundryId = environment.getProperty("vcap.application.instance_id", String.class);
    if (cloudFoundryId.isPresent()) {
      return cloudFoundryId.get();
    } else {
      StringJoiner joiner = new StringJoiner(":");
      String applicationName = serviceInstance.getId();

      joiner.add(applicationName);
      if (serviceInstance instanceof EmbeddedServerInstance) {
        EmbeddedServerInstance esi = (EmbeddedServerInstance) serviceInstance;
        Optional<String> id = esi.getEmbeddedServer().getApplicationConfiguration().getInstance().getId();
        if (id.isPresent()) {
          joiner.add(id.get());
        } else {
          joiner.add(String.valueOf(esi.getPort()));
        }
      } else {
        joiner.add(String.valueOf(serviceInstance.getPort()));
      }

      return joiner.toString();
    }
  }
}

代码示例来源:origin: io.micronaut.configuration/micronaut-hibernate-validator

Optional<Properties> config = env.getProperty("hibernate.validator", Properties.class);
config.ifPresent(properties -> {
  for (Map.Entry<Object, Object> entry : properties.entrySet()) {

相关文章