Example usage for org.springframework.core.env ConfigurableEnvironment getConversionService

List of usage examples for org.springframework.core.env ConfigurableEnvironment getConversionService

Introduction

In this page you can find the example usage for org.springframework.core.env ConfigurableEnvironment getConversionService.

Prototype

ConfigurableConversionService getConversionService();

Source Link

Document

Return the ConfigurableConversionService used when performing type conversions on properties.

Usage

From source file:com.teradata.benchto.driver.utils.PropertiesUtils.java

public static <T> T resolveEnvironmentProperties(ConfigurableEnvironment environment, Class<T> clazz,
        String prefix) {//  w  w w .  j a v a  2 s .c  o m
    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);
    }
}

From source file:com.capgemini.boot.core.factory.internal.SpringBootSettingsResolver.java

@SuppressWarnings("unchecked")
@Override//from   w ww .j av a  2 s.  com
public <T> T resolveSettings(Class<T> settingsClass, String prefix, ConfigurableEnvironment environment) {
    try {
        T newSettings = (T) Class.forName(settingsClass.getName()).newInstance();

        PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(
                newSettings);
        factory.setTargetName(prefix);
        factory.setPropertySources(environment.getPropertySources());
        factory.setConversionService(environment.getConversionService());
        factory.bindPropertiesToTarget();

        return newSettings;
    } catch (Exception ex) {
        throw new FatalBeanException("Could not bind DataSourceSettings properties", ex);
    }
}