-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Closed
Description
When the RelaxedPropertyResolver has multiple property sources, the subProperties() method does not return the same property values as getProperty(). The getProperty() method returns the value from the first property source that defines it whereas the subProperties() method returns the value from the last property source that defines it. Here is a test case:
import java.util.Map;
import java.util.Properties;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;
public class SubPropertiesTest {
@Test
public void testPropertySource() throws Exception {
String propertyPrefix = "spring.datasource.";
String propertyName = "password";
String fullPropertyName = propertyPrefix + propertyName;
System.setProperty(fullPropertyName, "systemPassword");
StandardEnvironment environment = new StandardEnvironment();
Properties properties = new Properties();
properties.put(fullPropertyName, "propertiesPassword");
PropertiesPropertySource propertySource = new PropertiesPropertySource("properties", properties);
environment.getPropertySources().addLast(propertySource);
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, propertyPrefix);
String directProperty = propertyResolver.getProperty(propertyName);
Map<String, Object> subProperties = propertyResolver.getSubProperties("");
String subProperty = (String) subProperties.get(propertyName);
Assert.assertEquals(directProperty, subProperty);
}
}
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug