Add support for UTF-8 in application.properties
Fixes gh-4622
This commit is contained in:
@@ -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",
|
||||
|
||||
1
spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties
vendored
Normal file
1
spring-boot/src/test/resources/org/springframework/boot/env/test-encoded.properties
vendored
Normal file
@@ -0,0 +1 @@
|
||||
test=prकperties
|
||||
Reference in New Issue
Block a user