From d6a424f94c4ed43dfee8b77f380de2529a256843 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 26 Nov 2015 15:09:50 +0000 Subject: [PATCH] Add support for UTF-8 in application.properties Fixes gh-4622 --- .../boot/env/PropertiesPropertySourceLoader.java | 4 +++- .../boot/env/PropertiesPropertySourceLoaderTests.java | 7 +++++++ .../org/springframework/boot/env/test-encoded.properties | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties diff --git a/spring-boot/src/main/java/org/springframework/boot/env/PropertiesPropertySourceLoader.java b/spring-boot/src/main/java/org/springframework/boot/env/PropertiesPropertySourceLoader.java index 7f3eb26668..d09e630aea 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/PropertiesPropertySourceLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/PropertiesPropertySourceLoader.java @@ -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); } diff --git a/spring-boot/src/test/java/org/springframework/boot/env/PropertiesPropertySourceLoaderTests.java b/spring-boot/src/test/java/org/springframework/boot/env/PropertiesPropertySourceLoaderTests.java index f5e08c24bf..6f719dfd51 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/PropertiesPropertySourceLoaderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/PropertiesPropertySourceLoaderTests.java @@ -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", diff --git a/spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties b/spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties new file mode 100644 index 0000000000..e135008619 --- /dev/null +++ b/spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties @@ -0,0 +1 @@ +test=prकperties \ No newline at end of file