Skip to content

Add support for UTF-8 and other charset/encoding to @PropertySource [SPR-13874] #18447

Closed
@spring-projects-issues

Description

@spring-projects-issues

Fyro opened SPR-13874 and commented

It seems that there is not currently support for encoding/charset in @PropertySource("classpath:/...").

With french characters like "Générales", current result is "Générales" because there is no check with charset/encoding.

Default constructor with default charset, it's ok.

public EncodedResource(Resource resource) {
     this(resource, null, Charset.defaultCharset());
}

Used in ConfigurationClassParser#processPropertySource

	/**
	 * Create a PropertySource having the given name based on Properties
	 * loaded from the given encoded resource.
	 */
	public ResourcePropertySource(String name, Resource resource) throws IOException {
		super(name, PropertiesLoaderUtils.loadProperties(new EncodedResource(resource)));
		this.resourceName = getNameForResource(resource);
	}

	/**
	 * Create a PropertySource based on Properties loaded from the given resource.
	 * The name of the PropertySource will be generated based on the
	 * {@link Resource#getDescription() description} of the given resource.
	 */
	public ResourcePropertySource(Resource resource) throws IOException {
		super(getNameForResource(resource), PropertiesLoaderUtils.loadProperties(new EncodedResource(resource)));
		this.resourceName = null;
	}

Affects: 4.2.4

Issue Links:

Referenced from: commits a3a5a03

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions