Placeholder configurers allow for trimming of property values
Issue: SPR-5839
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,6 +107,8 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
|
||||
/** Defaults to {@value #DEFAULT_VALUE_SEPARATOR} */
|
||||
protected String valueSeparator = DEFAULT_VALUE_SEPARATOR;
|
||||
|
||||
protected boolean trimValues = false;
|
||||
|
||||
protected String nullValue;
|
||||
|
||||
protected boolean ignoreUnresolvablePlaceholders = false;
|
||||
@@ -142,6 +144,16 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
|
||||
this.valueSeparator = valueSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to trim resolved values before applying them,
|
||||
* removing superfluous whitespace from the beginning and end.
|
||||
* <p>Default is {@code false}.
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setTrimValues(boolean trimValues) {
|
||||
this.trimValues = trimValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value that should be treated as {@code null} when resolved
|
||||
* as a placeholder value: e.g. "" (empty String) or "null".
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -255,8 +255,11 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
|
||||
|
||||
@Override
|
||||
public String resolveStringValue(String strVal) throws BeansException {
|
||||
String value = this.helper.replacePlaceholders(strVal, this.resolver);
|
||||
return (value.equals(nullValue) ? null : value);
|
||||
String resolved = this.helper.replacePlaceholders(strVal, this.resolver);
|
||||
if (trimValues) {
|
||||
resolved = resolved.trim();
|
||||
}
|
||||
return (resolved.equals(nullValue) ? null : resolved);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user