use of org.springframework.core.env.PropertySource in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method withNonEnumerablePropertySource.
@Test
public void withNonEnumerablePropertySource() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${foo}").getBeanDefinition());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
PropertySource<?> ps = new PropertySource<Object>("simplePropertySource", new Object()) {
@Override
public Object getProperty(String key) {
return "bar";
}
};
MockEnvironment env = new MockEnvironment();
env.getPropertySources().addFirst(ps);
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("bar"));
}
use of org.springframework.core.env.PropertySource in project libresonic by Libresonic.
the class LoggingFileOverrideListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
PropertySource ps = new MapPropertySource("LogFileLocationPS", Collections.singletonMap(LogFile.FILE_PROPERTY, getLogFile().getAbsolutePath()));
event.getEnvironment().getPropertySources().addLast(ps);
}
use of org.springframework.core.env.PropertySource in project java-chassis by ServiceComb.
the class ConfigurableEnvironmentConfiguration method getPropertySources.
private Map<String, PropertySource<?>> getPropertySources() {
Map<String, PropertySource<?>> map = new LinkedHashMap<>();
MutablePropertySources sources = (this.environment != null ? this.environment.getPropertySources() : new StandardEnvironment().getPropertySources());
for (PropertySource<?> source : sources) {
extract("", map, source);
}
return map;
}
use of org.springframework.core.env.PropertySource in project bitsquare by bitsquare.
the class BitsquareEnvironmentTests method testPropertySourcePrecedence.
@Test
public void testPropertySourcePrecedence() {
PropertySource commandlineProps = new MockPropertySource(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME).withProperty("key.x", "x.commandline");
PropertySource filesystemProps = new MockPropertySource(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME).withProperty("key.x", "x.env").withProperty("key.y", "y.env");
ConfigurableEnvironment env = new BitsquareEnvironment(commandlineProps) {
@Override
PropertySource<?> appDirProperties() {
return filesystemProps;
}
};
MutablePropertySources propertySources = env.getPropertySources();
assertThat(propertySources.precedenceOf(named(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(propertySources.precedenceOf(named(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(propertySources.precedenceOf(named(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(propertySources.precedenceOf(named(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(propertySources.precedenceOf(named(BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(propertySources.precedenceOf(named(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(5));
assertThat(propertySources.precedenceOf(named(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(6));
assertThat(propertySources.size(), equalTo(7));
// commandline value wins due to precedence
assertThat(env.getProperty("key.x"), equalTo("x.commandline"));
// env value wins because it's the only one available
assertThat(env.getProperty("key.y"), equalTo("y.env"));
}
use of org.springframework.core.env.PropertySource in project grails-core by grails.
the class EnvironmentAwarePropertySource method initialize.
private void initialize() {
if (propertyNames == null) {
propertyNames = new ArrayList<>();
Environment env = Environment.getCurrent();
String key = "environments." + env.getName();
for (PropertySource propertySource : source) {
if ((propertySource != this) && // plugin default configuration is not allowed to be environment aware (GRAILS-12123)
!propertySource.getName().contains("plugin") && propertySource instanceof EnumerablePropertySource) {
EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource;
for (String propertyName : enumerablePropertySource.getPropertyNames()) {
if (propertyName.startsWith(key) && propertyName.length() > key.length()) {
propertyNames.add(propertyName.substring(key.length() + 1));
}
}
}
}
}
}
Aggregations