@@ -56,12 +56,15 @@ public class PropertySourcesPropertyValues implements PropertyValues {
56
56
57
57
private final ConcurrentHashMap <String , PropertySource <?>> collectionOwners = new ConcurrentHashMap <String , PropertySource <?>>();
58
58
59
+ private boolean resolvePlaceholders = true ;
60
+
59
61
/**
60
62
* Create a new PropertyValues from the given PropertySources.
61
63
* @param propertySources a PropertySources instance
62
64
*/
63
65
public PropertySourcesPropertyValues (PropertySources propertySources ) {
64
- this (propertySources , (Collection <String >) null , PropertyNamePatternsMatcher .ALL );
66
+ this (propertySources , (Collection <String >) null , PropertyNamePatternsMatcher .ALL ,
67
+ true );
65
68
}
66
69
67
70
/**
@@ -76,7 +79,7 @@ public PropertySourcesPropertyValues(PropertySources propertySources,
76
79
Collection <String > includePatterns ,
77
80
Collection <String > nonEnumerableFallbackNames ) {
78
81
this (propertySources , nonEnumerableFallbackNames ,
79
- new PatternPropertyNamePatternsMatcher (includePatterns ));
82
+ new PatternPropertyNamePatternsMatcher (includePatterns ), true );
80
83
}
81
84
82
85
/**
@@ -85,22 +88,34 @@ public PropertySourcesPropertyValues(PropertySources propertySources,
85
88
* @param nonEnumerableFallbackNames the property names to try in lieu of an
86
89
* {@link EnumerablePropertySource}.
87
90
* @param includes the property name patterns to include
91
+ * @param resolvePlaceholders flag to indicate the placeholders should be resolved
88
92
*/
89
93
PropertySourcesPropertyValues (PropertySources propertySources ,
90
94
Collection <String > nonEnumerableFallbackNames ,
91
- PropertyNamePatternsMatcher includes ) {
95
+ PropertyNamePatternsMatcher includes , boolean resolvePlaceholders ) {
92
96
Assert .notNull (propertySources , "PropertySources must not be null" );
93
97
Assert .notNull (includes , "Includes must not be null" );
94
98
this .propertySources = propertySources ;
95
99
this .nonEnumerableFallbackNames = nonEnumerableFallbackNames ;
96
100
this .includes = includes ;
101
+ this .resolvePlaceholders = resolvePlaceholders ;
97
102
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver (
98
103
propertySources );
99
104
for (PropertySource <?> source : propertySources ) {
100
105
processPropertySource (source , resolver );
101
106
}
102
107
}
103
108
109
+ /**
110
+ * Flag to indicate that placeholders should be replaced during binding. Default is
111
+ * true.
112
+ *
113
+ * @param resolvePlaceholders flag value
114
+ */
115
+ public void setResolvePlaceholders (boolean resolvePlaceholders ) {
116
+ this .resolvePlaceholders = resolvePlaceholders ;
117
+ }
118
+
104
119
private void processPropertySource (PropertySource <?> source ,
105
120
PropertySourcesPropertyResolver resolver ) {
106
121
if (source instanceof CompositePropertySource ) {
@@ -138,12 +153,14 @@ private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
138
153
private Object getEnumerableProperty (EnumerablePropertySource <?> source ,
139
154
PropertySourcesPropertyResolver resolver , String propertyName ) {
140
155
try {
141
- return resolver .getProperty (propertyName , Object .class );
156
+ if (this .resolvePlaceholders ) {
157
+ return resolver .getProperty (propertyName , Object .class );
158
+ }
142
159
}
143
160
catch (RuntimeException ex ) {
144
161
// Probably could not resolve placeholders, ignore it here
145
- return source .getProperty (propertyName );
146
162
}
163
+ return source .getProperty (propertyName );
147
164
}
148
165
149
166
private void processNonEnumerablePropertySource (PropertySource <?> source ,
0 commit comments