Example usage for org.springframework.boot.context.event ApplicationEnvironmentPreparedEvent getEnvironment

List of usage examples for org.springframework.boot.context.event ApplicationEnvironmentPreparedEvent getEnvironment

Introduction

In this page you can find the example usage for org.springframework.boot.context.event ApplicationEnvironmentPreparedEvent getEnvironment.

Prototype

public ConfigurableEnvironment getEnvironment() 

Source Link

Document

Return the environment.

Usage

From source file:gov.uscis.vis.api.config.SwaggerPropertiesLoader.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment env = event.getEnvironment();
    env.getPropertySources().addLast(new PropertiesPropertySource("swagger", createSwaggerProperties(env)));
}

From source file:io.fabric8.spring.cloud.kubernetes.profile.KubernetesProfileApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment environment = event.getEnvironment();
    addKubernetesProfile(environment);/*from   w  ww. j a  v  a 2  s .c  o m*/
}

From source file:org.cloudfoundry.reconfiguration.spring.CloudProfileApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment environment = event.getEnvironment();
    addCloudProfile(environment);//from w  w w  . j  a  v a  2  s.  co  m
}

From source file:com.ecsteam.cloudlaunch.environment.VcapEnvironmentListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    Map<String, Object> properties = new RelaxedPropertyResolver(event.getEnvironment())
            .getSubProperties("vcap.services.");

    if (properties == null || properties.isEmpty()) {
        return;//from  w  w  w  . j  a  va  2 s  .  c  o m
    }

    Map<String, Object> source = new HashMap<String, Object>();

    source.put("ecs.cc.user", "${vcap.services.${ecs.cc.serviceId:cc}.credentials.user}");
    source.put("ecs.cc.password", "${vcap.services.${ecs.cc.serviceId:cc}.credentials.password}");
    source.put("ecs.cc.url", "${vcap.services.${ecs.cc.serviceId:cc}.credentials.url}");
    source.put("ecs.cc.trustSelfSigned",
            "${vcap.services.${ecs.cc.serviceId:cc}.credentials.trustSelfSigned:false}");

    source.put("ecs.jenkins.baseUrl", "${vcap.services.${ecs.jenkins.serviceId:jenkins}.credentials.baseUrl}");
    source.put("ecs.jenkins.jobName", "${vcap.services.${ecs.jenkins.serviceId:jenkins}.credentials.jobName}");
    source.put("ecs.jenkins.user", "${vcap.services.${ecs.jenkins.serviceId:jenkins}.credentials.user}");
    source.put("ecs.jenkins.password",
            "${vcap.services.${ecs.jenkins.serviceId:jenkins}.credentials.password}");

    source.put("ecs.github.clientId", "${vcap.services.${ecs.github.serviceId:github}.credentials.clientId}");
    source.put("ecs.github.clientSecret",
            "${vcap.services.${ecs.github.serviceId:github}.credentials.clientSecret}");
    source.put("ecs.github.repoName", "${vcap.services.${ecs.github.serviceId:github}.credentials.repoName}");
    source.put("ecs.github.repoOwner", "${vcap.services.${ecs.github.serviceId:github}.credentials.repoOwner}");
    source.put("ecs.github.accessToken",
            "${vcap.services.${ecs.github.serviceId:github}.credentials.accessToken}");

    event.getEnvironment().getPropertySources()
            .addLast(new MapPropertySource("ecsCloudLaunchProperties", source));
}

From source file:com.example.autoconfigure.listener.ExampleApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    System.err.println("Adding extra properties");
    PropertySource<?> propertySource = new MapPropertySource("example",
            Collections.singletonMap("example.secret", "the-secret-key"));
    event.getEnvironment().getPropertySources().addFirst(propertySource);
}

From source file:org.springframework.boot.cloudfoundry.VcapApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment environment = event.getEnvironment();
    if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) {
        return;//from w w w. j  a v  a  2 s  .co m
    }
    Properties properties = new Properties();
    addWithPrefix(properties, getPropertiesFromApplication(environment), "vcap.application.");
    addWithPrefix(properties, getPropertiesFromServices(environment), "vcap.services.");
    MutablePropertySources propertySources = environment.getPropertySources();
    if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
        propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
                new PropertiesPropertySource("vcap", properties));
    } else {
        propertySources.addFirst(new PropertiesPropertySource("vcap", properties));
    }
}

From source file:org.springframework.boot.context.config.ConfigFileApplicationListener.java

private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
    List<EnvironmentPostProcessor> postProcessors = SpringFactoriesLoader
            .loadFactories(EnvironmentPostProcessor.class, getClass().getClassLoader());
    postProcessors.add(this);
    for (EnvironmentPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessEnvironment(event.getEnvironment(), event.getSpringApplication());
    }//  w ww.ja  v  a2s .  c om
}

From source file:org.springframework.boot.context.FileEncodingApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(event.getEnvironment(), "spring.");
    if (resolver.containsProperty("mandatoryFileEncoding")) {
        String encoding = System.getProperty("file.encoding");
        String desired = resolver.getProperty("mandatoryFileEncoding");
        if (encoding != null && !desired.equalsIgnoreCase(encoding)) {
            logger.error("System property 'file.encoding' is currently '" + encoding + "'. It should be '"
                    + desired + "' (as defined in 'spring.mandatoryFileEncoding').");
            logger.error("Environment variable LANG is '" + System.getenv("LANG")
                    + "'. You could use a locale setting that matches encoding='" + desired + "'.");
            logger.error("Environment variable LC_ALL is '" + System.getenv("LC_ALL")
                    + "'. You could use a locale setting that matches encoding='" + desired + "'.");
            throw new IllegalStateException("The Java Virtual Machine has not been configured to use the "
                    + "desired default character encoding (" + desired + ").");
        }/*from www  . j  av  a  2s.  c o m*/
    }
}

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

private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
    if (this.loggingSystem == null) {
        this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader());
    }/* www.  ja v  a2s  . c om*/
    initialize(event.getEnvironment(), event.getSpringApplication().getClassLoader());
}

From source file:org.springframework.yarn.boot.support.YarnBootClientApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    MutablePropertySources propertySources = event.getEnvironment().getPropertySources();
    if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
        if (log.isDebugEnabled()) {
            log.debug("Adding afterCommandLineArgs property source after "
                    + CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME);
        }/*  w ww  .  j  a  va2  s .  com*/
        propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
                new MapPropertySource("afterCommandLineArgs", propertySourceMap));
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Adding afterCommandLineArgs property source as first");
        }
        propertySources.addFirst(new MapPropertySource("afterCommandLineArgs", propertySourceMap));
    }
}