Merge branch '1.3.x'
This commit is contained in:
@@ -22,7 +22,6 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +41,7 @@ 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
|
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
|
||||||
.loadProperties(new EncodedResource(resource, "UTF-8"));
|
|
||||||
if (!properties.isEmpty()) {
|
if (!properties.isEmpty()) {
|
||||||
return new PropertiesPropertySource(name, properties);
|
return new PropertiesPropertySource(name, properties);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,8 @@ import org.junit.Test;
|
|||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link PropertiesPropertySourceLoader}.
|
* Tests for {@link PropertiesPropertySourceLoader}.
|
||||||
@@ -34,28 +35,22 @@ public class PropertiesPropertySourceLoaderTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFileExtensions() throws Exception {
|
public void getFileExtensions() throws Exception {
|
||||||
assertThat(this.loader.getFileExtensions()).containsExactly("properties", "xml");
|
assertThat(this.loader.getFileExtensions(),
|
||||||
|
equalTo(new String[] { "properties", "xml" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadProperties() throws Exception {
|
public void loadProperties() throws Exception {
|
||||||
PropertySource<?> source = this.loader.load("test.properties",
|
PropertySource<?> source = this.loader.load("test.properties",
|
||||||
new ClassPathResource("test-properties.properties", getClass()), null);
|
new ClassPathResource("test-properties.properties", getClass()), null);
|
||||||
assertThat(source.getProperty("test")).isEqualTo("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")).isEqualTo("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",
|
||||||
new ClassPathResource("test-xml.xml", getClass()), null);
|
new ClassPathResource("test-xml.xml", getClass()), null);
|
||||||
assertThat(source.getProperty("test")).isEqualTo("xml");
|
assertThat(source.getProperty("test"), equalTo((Object) "xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
test=prकperties
|
|
||||||
Reference in New Issue
Block a user