From efa7ad837012566255f086caa07689199d900b34 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 28 Apr 2015 11:47:50 +0100 Subject: [PATCH] Only use PropertySource.getValue() as a fallback It converts everything to a String so it isn't helpful to use it as a default. Fixes gh-2891. --- .../boot/bind/PropertySourcesPropertyValues.java | 7 +++++-- .../boot/bind/PropertySourcesPropertyValuesTests.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java index 9cd21f3c3b3..83a87a8b854 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java @@ -121,12 +121,15 @@ public class PropertySourcesPropertyValues implements PropertyValues { .contains(source.getName()) && !includes.matches(propertyName)) { continue; } - Object value = source.getProperty(propertyName); + Object value = null; try { - value = resolver.getProperty(propertyName); + value = resolver.getProperty(propertyName, Object.class); } catch (RuntimeException ex) { // Probably could not resolve placeholders, ignore it here + if (value == null) { + value = source.getProperty(propertyName); + } } if (!this.propertyValues.containsKey(propertyName)) { this.propertyValues.put(propertyName, new PropertyValue(propertyName, diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java index 7fbb5251379..afd1240884b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java @@ -57,6 +57,17 @@ public class PropertySourcesPropertyValuesTests { . singletonMap("name", "${foo}"))); } + @Test + public void testTypesPreserved() { + this.propertySources.replace( + "map", + new MapPropertySource("map", Collections. singletonMap( + "name", 123))); + PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues( + this.propertySources); + assertEquals(123, propertyValues.getPropertyValues()[0].getValue()); + } + @Test public void testSize() { PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(