Add support for RelaxedDataBinder aliases

Update RelaxedDataBinder to support property aliases and change
DataSourceBuilder to use them.

Fixes gh-1384
This commit is contained in:
Phillip Webb
2014-08-15 10:46:06 -07:00
parent a6e6e1e07a
commit 8476a79dd2
3 changed files with 72 additions and 17 deletions

View File

@@ -23,7 +23,6 @@ import javax.sql.DataSource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.util.ClassUtils;
@@ -84,15 +83,8 @@ public class DataSourceBuilder {
}
private void bind(DataSource result) {
new RelaxedDataBinder(result).bind(getPropertyValues());
}
private PropertyValues getPropertyValues() {
if (getType().getName().contains("Hikari") && this.properties.containsKey("url")) {
this.properties.put("jdbcUrl", this.properties.get("url"));
this.properties.remove("url");
}
return new MutablePropertyValues(this.properties);
MutablePropertyValues properties = new MutablePropertyValues(this.properties);
new RelaxedDataBinder(result).withAlias("url", "jdbcUrl").bind(properties);
}
public DataSourceBuilder type(Class<? extends DataSource> type) {