Java Code Examples for org.springframework.core.env.ConfigurableEnvironment#addActiveProfile()

The following examples show how to use org.springframework.core.env.ConfigurableEnvironment#addActiveProfile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebapiApplicationRunListener.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    String profiles = environment.getProperty("spring.profiles.active");
    List<String> productProfiles = Arrays.asList("prod", "product");
    if (environment.containsProperty(PLATFORM_PROFILE_PRODUCT_NAME)) {
        productProfiles = Arrays.asList(environment.getProperty(PLATFORM_PROFILE_PRODUCT_NAME));
    }
    if (!StringUtils.isEmpty(profiles)) {
        if (productProfiles.stream().anyMatch(p -> profiles.toLowerCase().contains(p.toLowerCase()))) {
            environment.addActiveProfile("noSwagger");
        } else {
            environment.addActiveProfile("swagger");
        }
    }else {
        // 不指定profile则默认开启swagger,开发机一般不指定
        environment.addActiveProfile("swagger");
    }
}
 
Example 2
Source File: IstioBootstrapConfiguration.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
void addIstioProfile(ConfigurableEnvironment environment) {
	if (this.utils.isIstioEnabled()) {
		if (hasIstioProfile(environment)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("'istio' already in list of active profiles");
			}
		}
		else {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Adding 'istio' to list of active profiles");
			}
			environment.addActiveProfile(ISTIO_PROFILE);
		}
	}
	else {
		if (LOG.isDebugEnabled()) {
			LOG.debug(
					"Not running inside kubernetes with istio enabled. Skipping 'istio' profile activation.");
		}
	}
}
 
Example 3
Source File: KubernetesProfileApplicationListener.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
void addKubernetesProfile(ConfigurableEnvironment environment) {
    Pod current = utils.currentPod().get();
    if (current != null) {
        if (!hasKubernetesProfile(environment)) {
            environment.addActiveProfile(KUBERNETES_PROFILE);
        }
    }

    if (utils.isInsideKubernetes()) {
        if (hasKubernetesProfile(environment)) {
            LOGGER.debug("'kubernetes' already in list of active profiles");
        } else {
            LOGGER.debug("Adding 'kubernetes' to list of active profiles");
            environment.addActiveProfile(KUBERNETES_PROFILE);
        }
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.warn("Not running inside kubernetes. Skipping 'kuberntes' profile activation.");
        }
    }
}
 
Example 4
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Cloud cloud = getCloud();

    ConfigurableEnvironment appEnvironment = applicationContext.getEnvironment();

    String[] persistenceProfiles = getCloudProfile(cloud);
    if (persistenceProfiles == null) {
        persistenceProfiles = getActiveProfile(appEnvironment);
    }
    if (persistenceProfiles == null) {
        persistenceProfiles = new String[] { IN_MEMORY_PROFILE };
    }

    for (String persistenceProfile : persistenceProfiles) {
        appEnvironment.addActiveProfile(persistenceProfile);
    }
}
 
Example 5
Source File: CustomerApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
	ConfigurableEnvironment applicationEnvironment = applicationContext.getEnvironment();
	Cloud cloud = getCloud();
	if (cloud != null) {
		applicationEnvironment.addActiveProfile("cloud");

	} else {
		applicationEnvironment.addActiveProfile("local");
	}

}
 
Example 6
Source File: ProductApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
	ConfigurableEnvironment applicationEnvironment = applicationContext.getEnvironment();
	Cloud cloud = getCloud();
	if (cloud != null) {
		applicationEnvironment.addActiveProfile("cloud");

	} else {
		applicationEnvironment.addActiveProfile("local");
	}

}
 
Example 7
Source File: KubernetesProfileEnvironmentPostProcessor.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {

	final boolean kubernetesEnabled = environment
			.getProperty("spring.cloud.kubernetes.enabled", Boolean.class, true);
	if (!kubernetesEnabled) {
		return;
	}

	if (isInsideKubernetes()) {
		if (hasKubernetesProfile(environment)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("'kubernetes' already in list of active profiles");
			}
		}
		else {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Adding 'kubernetes' to list of active profiles");
			}
			environment.addActiveProfile(KUBERNETES_PROFILE);
		}
	}
	else {
		if (LOG.isDebugEnabled()) {
			LOG.warn(
					"Not running inside kubernetes. Skipping 'kubernetes' profile activation.");
		}
	}
}
 
Example 8
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Cloud cloud = getCloud();

    ConfigurableEnvironment appEnvironment = applicationContext.getEnvironment();

    String[] persistenceProfiles = getCloudProfiles(cloud);
    if (persistenceProfiles == null) {
        persistenceProfiles = new String[] { IN_MEMORY_PROFILE };
    }

    for (String persistenceProfile : persistenceProfiles) {
        appEnvironment.addActiveProfile(persistenceProfile);
    }
}
 
Example 9
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Cloud cloud = getCloud();

    ConfigurableEnvironment appEnvironment = applicationContext.getEnvironment();

    String[] persistenceProfiles = getCloudProfiles(cloud);
    if (persistenceProfiles == null) {
        persistenceProfiles = new String[] { IN_MEMORY_PROFILE };
    }

    for (String persistenceProfile : persistenceProfiles) {
        appEnvironment.addActiveProfile(persistenceProfile);
    }
}