Search in sources :

Example 1 with PropertyResolver

use of cn.taketoday.core.env.PropertyResolver in project today-infrastructure by TAKETODAY.

the class ConfigurationPropertySourcesTests method attachShouldAddAdapterAtBeginning.

@Test
void attachShouldAddAdapterAtBeginning() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    PropertySources sources = environment.getPropertySources();
    sources.addLast(new SystemEnvironmentPropertySource("system", Collections.singletonMap("SERVER_PORT", "1234")));
    sources.addLast(new MapPropertySource("config", Collections.singletonMap("server.port", "4568")));
    int size = sources.size();
    ConfigurationPropertySources.attach(environment);
    assertThat(sources.size()).isEqualTo(size + 1);
    PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
    assertThat(resolver.getProperty("server.port")).isEqualTo("1234");
}
Also used : PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) PropertySources(cn.taketoday.core.env.PropertySources) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertyResolver(cn.taketoday.core.env.PropertyResolver) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 2 with PropertyResolver

use of cn.taketoday.core.env.PropertyResolver in project today-framework by TAKETODAY.

the class ResourceBanner method printBanner.

@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
    try {
        String banner = StreamUtils.copyToString(this.resource.getInputStream(), environment.getProperty("banner.charset", Charset.class, StandardCharsets.UTF_8));
        for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
            banner = resolver.resolvePlaceholders(banner);
        }
        out.println(banner);
    } catch (Exception ex) {
        logger.warn("Banner not printable: %s (%s: '%s')", this.resource, ex.getClass(), ex.getMessage(), ex);
    }
}
Also used : Charset(java.nio.charset.Charset) PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertyResolver(cn.taketoday.core.env.PropertyResolver)

Example 3 with PropertyResolver

use of cn.taketoday.core.env.PropertyResolver in project today-framework by TAKETODAY.

the class ConfigurationPropertySourcesTests method attachShouldAddAdapterAtBeginning.

@Test
void attachShouldAddAdapterAtBeginning() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    PropertySources sources = environment.getPropertySources();
    sources.addLast(new SystemEnvironmentPropertySource("system", Collections.singletonMap("SERVER_PORT", "1234")));
    sources.addLast(new MapPropertySource("config", Collections.singletonMap("server.port", "4568")));
    int size = sources.size();
    ConfigurationPropertySources.attach(environment);
    assertThat(sources.size()).isEqualTo(size + 1);
    PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
    assertThat(resolver.getProperty("server.port")).isEqualTo("1234");
}
Also used : PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) PropertySources(cn.taketoday.core.env.PropertySources) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertyResolver(cn.taketoday.core.env.PropertyResolver) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with PropertyResolver

use of cn.taketoday.core.env.PropertyResolver in project today-infrastructure by TAKETODAY.

the class ResourceBanner method printBanner.

@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
    try {
        String banner = StreamUtils.copyToString(this.resource.getInputStream(), environment.getProperty("banner.charset", Charset.class, StandardCharsets.UTF_8));
        for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
            banner = resolver.resolvePlaceholders(banner);
        }
        out.println(banner);
    } catch (Exception ex) {
        logger.warn("Banner not printable: %s (%s: '%s')", this.resource, ex.getClass(), ex.getMessage(), ex);
    }
}
Also used : Charset(java.nio.charset.Charset) PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertyResolver(cn.taketoday.core.env.PropertyResolver)

Aggregations

PropertyResolver (cn.taketoday.core.env.PropertyResolver)4 PropertySourcesPropertyResolver (cn.taketoday.core.env.PropertySourcesPropertyResolver)4 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)2 MapPropertySource (cn.taketoday.core.env.MapPropertySource)2 PropertySources (cn.taketoday.core.env.PropertySources)2 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)2 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)2 Charset (java.nio.charset.Charset)2 Test (org.junit.jupiter.api.Test)2