|  | 
| 24 | 24 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | 
| 25 | 25 | import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; | 
| 26 | 26 | import org.springframework.context.EnvironmentAware; | 
|  | 27 | +import org.springframework.core.convert.ConversionService; | 
|  | 28 | +import org.springframework.core.convert.support.DefaultConversionService; | 
| 27 | 29 | import org.springframework.core.env.ConfigurableEnvironment; | 
| 28 | 30 | import org.springframework.core.env.ConfigurablePropertyResolver; | 
| 29 | 31 | import org.springframework.core.env.Environment; | 
| @@ -247,12 +249,33 @@ public Object getProperty(String name) { | 
| 247 | 249 | 			for (PropertySource<?> propertySource : super.source.getPropertySources()) { | 
| 248 | 250 | 				Object candidate = propertySource.getProperty(name); | 
| 249 | 251 | 				if (candidate != null) { | 
| 250 |  | -					return candidate; | 
|  | 252 | +					return convertToString(candidate); | 
| 251 | 253 | 				} | 
| 252 | 254 | 			} | 
| 253 | 255 | 			return null; | 
| 254 | 256 | 		} | 
| 255 | 257 | 
 | 
|  | 258 | +		/** | 
|  | 259 | +		 * Convert the supplied value to a {@link String} using the {@link ConversionService} | 
|  | 260 | +		 * from the {@link Environment}. | 
|  | 261 | +		 * <p>This is a modified version of | 
|  | 262 | +		 * {@link org.springframework.core.env.AbstractPropertyResolver#convertValueIfNecessary(Object, Class)}. | 
|  | 263 | +		 * @param value the value to convert | 
|  | 264 | +		 * @return the converted value, or the original value if no conversion is necessary | 
|  | 265 | +		 * @since 6.2.8 | 
|  | 266 | +		 */ | 
|  | 267 | +		@Nullable | 
|  | 268 | +		private String convertToString(Object value) { | 
|  | 269 | +			if (value instanceof String string) { | 
|  | 270 | +				return string; | 
|  | 271 | +			} | 
|  | 272 | +			ConversionService conversionService = super.source.getConversionService(); | 
|  | 273 | +			if (conversionService == null) { | 
|  | 274 | +				conversionService = DefaultConversionService.getSharedInstance(); | 
|  | 275 | +			} | 
|  | 276 | +			return conversionService.convert(value, String.class); | 
|  | 277 | +		} | 
|  | 278 | + | 
| 256 | 279 | 		@Override | 
| 257 | 280 | 		public String toString() { | 
| 258 | 281 | 			return "ConfigurableEnvironmentPropertySource {propertySources=" + super.source.getPropertySources() + "}"; | 
|  | 
0 commit comments