Example usage for org.springframework.core.env Environment getProperty

List of usage examples for org.springframework.core.env Environment getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env Environment getProperty.

Prototype

<T> T getProperty(String key, Class<T> targetType, T defaultValue);

Source Link

Document

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Usage

From source file:org.springframework.boot.context.logging.LoggingApplicationListener.java

private void registerShutdownHookIfNecessary(Environment environment, LoggingSystem loggingSystem) {
    boolean registerShutdownHook = environment.getProperty(REGISTER_SHUTDOWN_HOOK_PROPERTY, Boolean.class,
            false);/*from   w  w  w  . jav  a 2 s .  c o m*/
    if (registerShutdownHook) {
        Runnable shutdownHandler = loggingSystem.getShutdownHandler();
        if (shutdownHandler != null && shutdownHookRegistered.compareAndSet(false, true)) {
            registerShutdownHook(new Thread(shutdownHandler));
        }
    }
}

From source file:org.springframework.boot.devtools.env.DevToolsPropertyDefaultsPostProcessor.java

private boolean canAddProperties(Environment environment) {
    if (environment.getProperty(ENABLED, Boolean.class, true)) {
        return isRestarterInitialized() || isRemoteRestartEnabled(environment);
    }/* ww  w  .  j  a va 2 s  . c  o m*/
    return false;
}

From source file:org.springframework.boot.ResourceBanner.java

@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
    try {/*from ww  w  . j  a v  a  2 s .c  o  m*/
        String banner = StreamUtils.copyToString(this.resource.getInputStream(),
                environment.getProperty("banner.charset", Charset.class, Charset.forName("UTF-8")));

        for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
            banner = resolver.resolvePlaceholders(banner);
        }
        out.println(banner);
    } catch (Exception ex) {
        log.warn("Banner not printable: " + this.resource + " (" + ex.getClass() + ": '" + ex.getMessage()
                + "')", ex);
    }
}