Commit d6a424f9 authored by Dave Syer's avatar Dave Syer

Add support for UTF-8 in application.properties

Fixes gh-4622
parent 9a60f740
...@@ -22,6 +22,7 @@ import java.util.Properties; ...@@ -22,6 +22,7 @@ import java.util.Properties;
import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.io.support.PropertiesLoaderUtils;
/** /**
...@@ -41,7 +42,8 @@ public class PropertiesPropertySourceLoader implements PropertySourceLoader { ...@@ -41,7 +42,8 @@ public class PropertiesPropertySourceLoader implements PropertySourceLoader {
public PropertySource<?> load(String name, Resource resource, String profile) public PropertySource<?> load(String name, Resource resource, String profile)
throws IOException { throws IOException {
if (profile == null) { if (profile == null) {
Properties properties = PropertiesLoaderUtils.loadProperties(resource); Properties properties = PropertiesLoaderUtils
.loadProperties(new EncodedResource(resource, "UTF-8"));
if (!properties.isEmpty()) { if (!properties.isEmpty()) {
return new PropertiesPropertySource(name, properties); return new PropertiesPropertySource(name, properties);
} }
......
...@@ -46,6 +46,13 @@ public class PropertiesPropertySourceLoaderTests { ...@@ -46,6 +46,13 @@ public class PropertiesPropertySourceLoaderTests {
assertThat(source.getProperty("test"), equalTo((Object) "properties")); assertThat(source.getProperty("test"), equalTo((Object) "properties"));
} }
@Test
public void loadPropertiesEncoded() throws Exception {
PropertySource<?> source = this.loader.load("encoded.properties",
new ClassPathResource("test-encoded.properties", getClass()), null);
assertThat(source.getProperty("test"), equalTo((Object) "prकperties"));
}
@Test @Test
public void loadXml() throws Exception { public void loadXml() throws Exception {
PropertySource<?> source = this.loader.load("test.xml", PropertySource<?> source = this.loader.load("test.xml",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment