下面列出了org.springframework.core.env.ConfigurableEnvironment#addActiveProfile ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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");
}
}
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.");
}
}
}
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.");
}
}
}
@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);
}
}
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment applicationEnvironment = applicationContext.getEnvironment();
Cloud cloud = getCloud();
if (cloud != null) {
applicationEnvironment.addActiveProfile("cloud");
} else {
applicationEnvironment.addActiveProfile("local");
}
}
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment applicationEnvironment = applicationContext.getEnvironment();
Cloud cloud = getCloud();
if (cloud != null) {
applicationEnvironment.addActiveProfile("cloud");
} else {
applicationEnvironment.addActiveProfile("local");
}
}
@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.");
}
}
}
@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);
}
}
@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);
}
}