Example usage for org.springframework.core.env ConfigurableEnvironment resolvePlaceholders

List of usage examples for org.springframework.core.env ConfigurableEnvironment resolvePlaceholders

Introduction

In this page you can find the example usage for org.springframework.core.env ConfigurableEnvironment resolvePlaceholders.

Prototype

String resolvePlaceholders(String text);

Source Link

Document

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by #getProperty .

Usage

From source file:bootstrap.EnvironmentBootstrapConfiguration.java

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    if (!environment.getPropertySources().contains(CONFIG_SERVER_BOOTSTRAP)) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("spring.cloud.config.uri",
                "${CONFIG_SERVER_URI:${vcap.services.${PREFIX:}configserver.credentials.uri:http://localhost:8888}}");
        if (ClassUtils.isPresent("org.springframework.cloud.sleuth.zipkin.ZipkinProperties", null)) {
            map.put("spring.zipkin.host",
                    "${ZIPKIN_HOST:${vcap.services.${PREFIX:}zipkin.credentials.host:localhost}}");
            map.put("logging.pattern.console",
                    "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex");
            String zipkinHost = environment
                    .resolvePlaceholders("${ZIPKIN_HOST:${vcap.services.${PREFIX:}zipkin.credentials.host:}}");
            if (!"".equals(zipkinHost)) {
                map.put("fleet.zipkin.enabled", "true");
            }//w  w w .  jav  a  2 s .  com
        }
        String space = environment.resolvePlaceholders("${vcap.application.space_name:dev}");
        log.info("Spacename: " + space);
        if (space.startsWith("dev")) {
            environment.addActiveProfile("dev");
        }
        map.put("encrypt.failOnError", "false");
        map.put("endpoints.shutdown.enabled", "true");
        map.put("endpoints.restart.enabled", "true");
        environment.getPropertySources().addLast(new MapPropertySource(CONFIG_SERVER_BOOTSTRAP, map));
    }
}

From source file:org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor.java

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    String json = environment.resolvePlaceholders("${spring.application.json:${SPRING_APPLICATION_JSON:}}");
    if (StringUtils.hasText(json)) {
        processJson(environment, json);//from  www.  j  av a2  s .  c o  m
    }
}