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

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

Introduction

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

Prototype

String[] getActiveProfiles();

Source Link

Document

Return the set of profiles explicitly made active for this environment.

Usage

From source file:uk.org.iay.mdq.server.Application.java

/**
 * Main entry point; invokes the web server using Spring Boot.
 * /*w  ww .j  a v a 2s.  co  m*/
 * @param args Command line arguments.
 */
public static void main(String[] args) {

    /*
     * Class logger.
     */
    final Logger log = LoggerFactory.getLogger(EntitiesController.class);

    /*
     * Construct the application.
     */
    final SpringApplication app = new SpringApplication(Application.class);

    /*
     * Customize the application.
     */
    app.setShowBanner(false);

    /*
     * Start the application.
     */
    final ApplicationContext ctx = app.run(args);

    final Environment env = ctx.getEnvironment();
    for (String profile : env.getDefaultProfiles()) {
        log.debug("default profile: {}", profile);
    }
    for (String profile : env.getActiveProfiles()) {
        log.debug("active profile: {}", profile);
    }
}

From source file:com.clicktravel.cheddar.server.runtime.config.RuntimeConfiguration.java

public static boolean isLocalOrDevEnvironment(final Environment environment) {
    for (final String profile : environment.getActiveProfiles()) {
        if (profile.equalsIgnoreCase(LOCAL_PROFILE) || profile.equalsIgnoreCase(DEV_PROFILE)) {
            return true;
        }/*w  ww  .j  a  va 2  s.co  m*/
    }
    return false;
}

From source file:com.clicktravel.cheddar.server.runtime.config.RuntimeConfiguration.java

public static boolean isDeployedEnvironment(final Environment environment) {
    for (final String profile : environment.getActiveProfiles()) {
        if (profile.equalsIgnoreCase(CI_PROFILE) || profile.equalsIgnoreCase(UAT_PROFILE)
                || profile.equalsIgnoreCase(PRODUCTION_PROFILE)) {
            return true;
        }/* w w w  . j a  va2  s  . co  m*/
    }
    return false;
}

From source file:com.otz.transport.config.FunnelPluginConfiguration.java

@Bean
public Cluster couchbaseCluster(Environment environment) {
    String clustersString = environment.getProperty(environment.getActiveProfiles()[0] + ".couchbase");
    String clusters[] = clustersString.split(",");
    return CouchbaseCluster.create(clusters);
}

From source file:org.eclipse.hono.example.AbstractExampleClient.java

@Autowired
public final void setActiveProfiles(final Environment env) {
    activeProfiles = Arrays.asList(env.getActiveProfiles());
}

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

private boolean hasKubernetesProfile(Environment environment) {
    for (String activeProfile : environment.getActiveProfiles()) {
        if (KUBERNETES_PROFILE.equalsIgnoreCase(activeProfile)) {
            return true;
        }//from  w  w w.  j  a v  a  2s .  co m
    }
    return false;
}

From source file:web.GeneratedBanner.java

private String getActiveProfiles(Environment environment) {
    return Joiner.on(", ").join(environment.getActiveProfiles());
}

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

private boolean hasCloudProfile(Environment environment) {
    for (String activeProfile : environment.getActiveProfiles()) {
        if (CLOUD_PROFILE.equalsIgnoreCase(activeProfile)) {
            return true;
        }//from   w  w  w .j  av a 2 s .c  o  m
    }

    return false;
}

From source file:com.otz.transport.config.TransportProducerConfiguration.java

@Bean(name = "KafkaProducerProperties")
public Properties kafkaProducerProperties(Environment environment) {
    String kafkaServer = environment.getProperty(environment.getActiveProfiles()[0] + KAFKA);

    Properties properties = new Properties();
    properties.put(RETRIES, environment.getProperty(TRANSPORT_RETRIES));
    properties.put(BATCH_SIZE, environment.getProperty(TRANSPORT_BATCH_SIZE));
    properties.put(TIMEOUT_MS, environment.getProperty(TRANSPORT_TIMEOUT_MS));
    properties.put(BUFFER_MEMORY, environment.getProperty(TRANSPORT_BUFFER_MEMORY));
    properties.put(ACK, environment.getProperty(TRANSPORT_ACK));
    properties.put(MAX_BLOCK, environment.getProperty(TRANSPORT_MAX_BLOCK));
    properties.put(KEY_SERIALIZER, environment.getProperty(TRANSPORT_KAFKA_KEY_SERIALIZER));
    properties.put(VALUE_SERIALIZER, environment.getProperty(TRANSPORT_KAFKA_VALUE_SERIALIZER));
    properties.put(BOOTSTRAP_SERVERS, kafkaServer);

    return properties;
}

From source file:com.otz.transport.config.EmailPluginConfiguration.java

@Bean
public EmailConfigParameters emailConfigParameters(Environment environment) {
    EmailConfigParameters emailConfigParameters = new EmailConfigParameters();

    String selectedEnvironment = environment.getActiveProfiles()[0];
    emailConfigParameters.setProtocol(//ww w  .jav a 2  s.  c  om
            environment.getProperty(selectedEnvironment + ".services.email.mail.transport.protocol"));
    emailConfigParameters
            .setAccessKey(environment.getProperty(selectedEnvironment + ".services.email.access.key"));
    emailConfigParameters
            .setSecretKey(environment.getProperty(selectedEnvironment + ".services.email.secret.key"));
    emailConfigParameters.setHost(environment.getProperty(selectedEnvironment + ".services.email.host"));
    emailConfigParameters.setPort(
            Integer.parseInt(environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.port")));
    emailConfigParameters.setSmtpAuth(Boolean
            .parseBoolean(environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.auth")));
    emailConfigParameters.setSmtpSslEnable(Boolean.parseBoolean(
            environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.ssl.enable")));

    return emailConfigParameters;
}