Search in sources :

Example 1 with ConfigurationPropertyNameAliases

use of org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases in project spring-boot by spring-projects.

the class XADataSourceAutoConfiguration method getBinderSource.

private ConfigurationPropertySource getBinderSource(DataSourceProperties dataSourceProperties) {
    Map<Object, Object> properties = new HashMap<>();
    properties.putAll(dataSourceProperties.getXa().getProperties());
    properties.computeIfAbsent("user", (key) -> dataSourceProperties.determineUsername());
    properties.computeIfAbsent("password", (key) -> dataSourceProperties.determinePassword());
    try {
        properties.computeIfAbsent("url", (key) -> dataSourceProperties.determineUrl());
    } catch (DataSourceBeanCreationException ex) {
    // Continue as not all XA DataSource's require a URL
    }
    MapConfigurationPropertySource source = new MapConfigurationPropertySource(properties);
    ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
    aliases.addAliases("user", "username");
    return source.withAliases(aliases);
}
Also used : HashMap(java.util.HashMap) DataSourceBeanCreationException(org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) ConfigurationPropertyNameAliases(org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases)

Aggregations

HashMap (java.util.HashMap)1 DataSourceBeanCreationException (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException)1 ConfigurationPropertyNameAliases (org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases)1 MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)1