66
66
import org .springframework .core .env .PropertySource ;
67
67
import org .springframework .core .io .Resource ;
68
68
import org .springframework .core .io .ResourceLoader ;
69
+ import org .springframework .core .io .support .EncodedResource ;
69
70
import org .springframework .core .io .support .ResourcePropertySource ;
70
71
import org .springframework .core .type .AnnotationMetadata ;
71
72
import org .springframework .core .type .MethodMetadata ;
@@ -354,16 +355,15 @@ private void processMemberClasses(ConfigurationClass configClass, SourceClass so
354
355
*/
355
356
private void processPropertySource (AnnotationAttributes propertySource ) throws IOException {
356
357
String name = propertySource .getString ("name" );
358
+ String encoding = propertySource .getString ("encoding" );
357
359
String [] locations = propertySource .getStringArray ("value" );
358
360
boolean ignoreResourceNotFound = propertySource .getBoolean ("ignoreResourceNotFound" );
359
361
Assert .isTrue (locations .length > 0 , "At least one @PropertySource(value) location is required" );
360
362
for (String location : locations ) {
361
363
try {
362
364
String resolvedLocation = this .environment .resolveRequiredPlaceholders (location );
363
365
Resource resource = this .resourceLoader .getResource (resolvedLocation );
364
- ResourcePropertySource rps = (StringUtils .hasText (name ) ?
365
- new ResourcePropertySource (name , resource ) : new ResourcePropertySource (resource ));
366
- addPropertySource (rps );
366
+ addPropertySource (createPropertySource (name , encoding , resource ));
367
367
}
368
368
catch (IllegalArgumentException ex ) {
369
369
// from resolveRequiredPlaceholders
@@ -380,6 +380,19 @@ private void processPropertySource(AnnotationAttributes propertySource) throws I
380
380
}
381
381
}
382
382
383
+ private ResourcePropertySource createPropertySource (String name , String encoding , Resource resource ) throws IOException {
384
+ if (StringUtils .hasText (name )) {
385
+ return (StringUtils .hasText (encoding ) ?
386
+ new ResourcePropertySource (name , new EncodedResource (resource , encoding )) :
387
+ new ResourcePropertySource (name , resource ));
388
+ }
389
+ else {
390
+ return (StringUtils .hasText (encoding ) ?
391
+ new ResourcePropertySource (new EncodedResource (resource , encoding )) :
392
+ new ResourcePropertySource (resource ));
393
+ }
394
+ }
395
+
383
396
private void addPropertySource (ResourcePropertySource propertySource ) {
384
397
String name = propertySource .getName ();
385
398
MutablePropertySources propertySources = ((ConfigurableEnvironment ) this .environment ).getPropertySources ();
0 commit comments