private StandardEnvironment convertEnvironment(ConfigurableEnvironment environment, Class<? extends StandardEnvironment> type) { StandardEnvironment result = createEnvironment(type); result.setActiveProfiles(environment.getActiveProfiles()); result.setConversionService(environment.getConversionService()); copyPropertySources(environment, result); return result; }
@Override public ConfigurableConversionService getConversionService() { return delegate.getConversionService(); }
@Override public ConfigurableConversionService getConversionService() { return delegate.getConversionService(); }
public NacosConfigLoader(ConfigurableEnvironment environment) { this.environment = environment; this.conversionService = environment.getConversionService(); this.resolver = new PropertiesPlaceholderResolver(environment); }
public NacosConfigLoader(ConfigurableEnvironment environment) { this.environment = environment; this.conversionService = environment.getConversionService(); this.resolver = new PropertiesPlaceholderResolver(environment); }
@Override public void afterPropertiesSet() { LOG.debug("Registering OpenHub converters."); Converters.registerConverters(env.getConversionService()); } }
private <T> T getAttribute(Element element, String name, T defaultValue) { ConversionService conversionService = environment.getConversionService(); String value = element.getAttribute(name); String resolvedValue = environment.resolvePlaceholders(value); T attributeValue = StringUtils.hasText(resolvedValue) ? (T) conversionService.convert(resolvedValue, defaultValue.getClass()) : defaultValue; return attributeValue; }
private <T> T getAttribute(Element element, String name, T defaultValue) { ConversionService conversionService = environment.getConversionService(); String value = element.getAttribute(name); String resolvedValue = environment.resolvePlaceholders(value); T attributeValue = StringUtils.hasText(resolvedValue) ? (T) conversionService.convert(resolvedValue, defaultValue.getClass()) : defaultValue; return attributeValue; }
private String convertValueToDurationIfPossible(final String value) { try { val service = applicationContext.getEnvironment().getConversionService(); val dur = service.convert(value, Duration.class); if (dur != null) { return String.valueOf(dur.toMillis()); } } catch (final ConversionFailedException e) { LOGGER.trace(e.getMessage()); } return null; } }
private Integer getResolvedValueIfPossible(ConfigurableEnvironment environment, String value) { String resolvedValue = environment.resolveRequiredPlaceholders(value); return environment.getConversionService().convert(resolvedValue, Integer.class); }
@Override @SneakyThrows public RiptideProperties parse(final ConfigurableEnvironment environment) { final PropertiesConfigurationFactory<RiptideProperties> factory = new PropertiesConfigurationFactory<>(RiptideProperties.class); factory.setTargetName("riptide"); factory.setPropertySources(environment.getPropertySources()); factory.setConversionService(environment.getConversionService()); return factory.getObject(); }
@Override @SneakyThrows public NakadiClientsProperties parse(ConfigurableEnvironment environment) { final PropertiesConfigurationFactory<NakadiClientsProperties> factory = new PropertiesConfigurationFactory<>(NakadiClientsProperties.class); factory.setTargetName("fahrschein"); factory.setPropertySources(environment.getPropertySources()); factory.setConversionService(environment.getConversionService()); return factory.getObject(); }
@Override @SneakyThrows public RiptideProperties parse(final ConfigurableEnvironment environment) { final PropertiesConfigurationFactory<RiptideProperties> factory = new PropertiesConfigurationFactory<>(RiptideProperties.class); factory.setTargetName("riptide"); factory.setPropertySources(environment.getPropertySources()); factory.setConversionService(environment.getConversionService()); return factory.getObject(); }
private Integer getPropertyAsInteger(PropertySource<?> source, String property, ConfigurableEnvironment environment) { Object value = source.getProperty(property); if (value == null) { return null; } if (ClassUtils.isAssignableValue(Integer.class, value)) { return (Integer) value; } try { return environment.getConversionService().convert(value, Integer.class); } catch (ConversionFailedException ex) { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return getResolvedValueIfPossible(environment, (String) value); } throw ex; } }
public static <T> T resolveEnvironmentProperties(ConfigurableEnvironment environment, Class<T> clazz, String prefix) { try { T properties = BeanUtils.instantiate(clazz); PropertiesConfigurationFactory<T> factory = new PropertiesConfigurationFactory<T>(properties); factory.setTargetName(prefix); factory.setPropertySources(environment.getPropertySources()); factory.setConversionService(environment.getConversionService()); factory.bindPropertiesToTarget(); return properties; } catch (BindException ex) { throw new FatalBeanException("Could not bind " + clazz + " properties", ex); } }
private <T> T getPropertiesConfigurationBean(String targetName, Class<T> types) { PropertiesConfigurationFactory<T> factory = new PropertiesConfigurationFactory<T>(types); factory.setPropertySources(environment.getPropertySources()); factory.setConversionService(environment.getConversionService()); factory.setIgnoreInvalidFields(true); factory.setIgnoreUnknownFields(true); factory.setIgnoreNestedProperties(false); factory.setTargetName(targetName); try { factory.bindPropertiesToTarget(); return factory.getObject(); } catch (Exception e) { throw new RuntimeException(e); } }