Add support for UTF-8 in application.properties

Fixes gh-4622
pull/4628/head
Dave Syer 9 years ago
parent 9a60f740b0
commit d6a424f94c

@ -22,6 +22,7 @@ import java.util.Properties;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
/**
@ -41,7 +42,8 @@ public class PropertiesPropertySourceLoader implements PropertySourceLoader {
public PropertySource<?> load(String name, Resource resource, String profile)
throws IOException {
if (profile == null) {
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
Properties properties = PropertiesLoaderUtils
.loadProperties(new EncodedResource(resource, "UTF-8"));
if (!properties.isEmpty()) {
return new PropertiesPropertySource(name, properties);
}

@ -46,6 +46,13 @@ public class PropertiesPropertySourceLoaderTests {
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
public void loadXml() throws Exception {
PropertySource<?> source = this.loader.load("test.xml",

Loading…
Cancel
Save