use of cn.taketoday.core.env.PropertySources in project today-framework by TAKETODAY.
the class AbstractApplicationEnvironmentTests method propertyResolverIsOptimizedForConfigurationProperties.
@Test
void propertyResolverIsOptimizedForConfigurationProperties() {
StandardEnvironment environment = createEnvironment();
ConfigurablePropertyResolver expected = ConfigurationPropertySources.createPropertyResolver(new PropertySources());
Object propertyResolver = PropertyAccessorFactory.forDirectFieldAccess(environment).getPropertyValue("propertyResolver");
assertThat(propertyResolver).isInstanceOf(expected.getClass());
}
use of cn.taketoday.core.env.PropertySources in project today-framework by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySources.
@Test
public void explicitPropertySources() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
PropertySources propertySources = new PropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
assertThat(propertySources.iterator().next()).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
}
use of cn.taketoday.core.env.PropertySources in project today-framework by TAKETODAY.
the class StandardEnvironmentTests method loadProperties.
@Test
void loadProperties() throws IOException {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources propertySources = environment.getPropertySources();
Properties properties = PropertiesUtils.loadProperties(ResourceUtils.getResource("classpath:info.properties"));
propertySources.addLast(new PropertiesPropertySource("info", properties));
assert "https://taketoday.cn".equals(environment.getProperty("site.host"));
}
use of cn.taketoday.core.env.PropertySources in project today-framework by TAKETODAY.
the class PropertySourcesDeducer method getPropertySources.
PropertySources getPropertySources() {
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
if (configurer != null) {
return configurer.getAppliedPropertySources();
}
PropertySources sources = extractEnvironmentPropertySources();
Assert.state(sources != null, "Unable to obtain PropertySources from PropertySourcesPlaceholderConfigurer or Environment");
return sources;
}
use of cn.taketoday.core.env.PropertySources in project today-framework by TAKETODAY.
the class ConfigurationPropertySources method get.
/**
* Return a set of {@link ConfigurationPropertySource} instances that have previously
* been {@link #attach(Environment) attached} to the {@link Environment}.
*
* @param environment the source environment (must be an instance of
* {@link ConfigurableEnvironment})
* @return an iterable set of configuration property sources
* @throws IllegalStateException if not configuration property sources have been
* attached
*/
public static Iterable<ConfigurationPropertySource> get(Environment environment) {
Assert.isInstanceOf(ConfigurableEnvironment.class, environment);
PropertySources sources = ((ConfigurableEnvironment) environment).getPropertySources();
ConfigurationPropertySourcesPropertySource attached = (ConfigurationPropertySourcesPropertySource) sources.get(ATTACHED_PROPERTY_SOURCE_NAME);
if (attached == null) {
return from(sources);
}
return attached.getSource();
}
Aggregations