List of usage examples for org.springframework.core.env ConfigurableEnvironment addActiveProfile
void addActiveProfile(String profile);
From source file:alfio.config.Initializer.java
@Override protected WebApplicationContext createRootApplicationContext() { ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext()); Objects.requireNonNull(ctx, "Something really bad is happening..."); ConfigurableEnvironment environment = ctx.getEnvironment(); if (environment.acceptsProfiles(PROFILE_DEV)) { environment.addActiveProfile(PROFILE_HTTP); }/*from www . ja v a2s . c om*/ this.environment = environment; return ctx; }
From source file:io.fabric8.spring.cloud.kubernetes.profile.KubernetesProfileApplicationListener.java
void addKubernetesProfile(ConfigurableEnvironment environment) { Pod current = utils.currentPod().get(); if (current != null) { if (!hasKubernetesProfile(environment)) { environment.addActiveProfile(KUBERNETES_PROFILE); }//from www . j a va 2 s .c o m } 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."); } } }
From source file:org.cloudfoundry.reconfiguration.spring.CloudProfileApplicationListener.java
void addCloudProfile(ConfigurableEnvironment environment) { if (this.cloudUtils.isInCloud()) { if (hasCloudProfile(environment)) { this.logger.fine("'cloud' already in list of active profiles"); } else {/* ww w. jav a2 s .co m*/ this.logger.info("Adding 'cloud' to list of active profiles"); environment.addActiveProfile(CLOUD_PROFILE); } } else { this.logger.warning("Not running in a cloud. Skipping 'cloud' profile activation."); } }
From source file:it.scoppelletti.programmerpower.web.spring.config.WebApplicationContextInitializer.java
/** * Inizializzazione.//from ww w . j a v a2 s . c om * * @param applCtx Contesto dell’applicazione. */ public void initialize(AbstractRefreshableWebApplicationContext applCtx) { ConfigurableEnvironment env; PropertySource<?> propSource; MutablePropertySources propSources; env = applCtx.getEnvironment(); // Acquisisco gli eventuali profili configurati prima di aggiungere // quelli di Programmer Power env.getActiveProfiles(); env.addActiveProfile(WebApplicationContextInitializer.PROFILE); env.addActiveProfile(DataUtils.PROFILE); propSources = env.getPropertySources(); propSource = BeanConfigUtils.loadPropertySource(); if (propSource != null) { propSources.addFirst(propSource); } propSources.addLast(new WebPropertySource(WebPropertySource.class.getName(), applCtx)); }
From source file:it.scoppelletti.programmerpower.console.spring.ConsoleApplicationRunner.java
/** * Inizializza il contesto dell’applicazione. * //from w ww . ja va2 s . com * @param ui Interfaccia utente. * @return Oggetto. */ private GenericApplicationContext initApplicationContext(UserInterfaceProvider ui) { SingletonBeanRegistry beanRegistry; GenericApplicationContext ctx = null; GenericApplicationContext applCtx; XmlBeanDefinitionReader reader; ConfigurableEnvironment env; PropertySource<?> propSource; MutablePropertySources propSources; try { ctx = new GenericApplicationContext(); reader = new XmlBeanDefinitionReader(ctx); reader.loadBeanDefinitions(ConsoleApplicationRunner.CONSOLE_CONTEXT); reader.loadBeanDefinitions(initApplicationContextResourceName()); beanRegistry = ctx.getBeanFactory(); beanRegistry.registerSingleton(ConsoleApplicationRunner.BEAN_NAME, this); beanRegistry.registerSingleton(UserInterfaceProvider.BEAN_NAME, ui); env = ctx.getEnvironment(); // Acquisisco gli eventuali profili configurati prima di aggiungere // quello di Programmer Power env.getActiveProfiles(); env.addActiveProfile(ConsoleApplicationRunner.PROFILE); propSources = env.getPropertySources(); propSources.addFirst(new ConsolePropertySource(ConsolePropertySource.class.getName(), this)); propSource = BeanConfigUtils.loadPropertySource(); if (propSource != null) { propSources.addFirst(propSource); } ctx.refresh(); applCtx = ctx; ctx = null; } finally { if (ctx != null) { ctx.close(); ctx = null; } } return applCtx; }
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"); }/*from w ww . j a va2 s.c om*/ } 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.cloud.kubernetes.profile.KubernetesProfileApplicationListener.java
void addKubernetesProfile(ConfigurableEnvironment environment) { Pod current = utils.currentPod().get(); if (current != null) { if (!hasKubernetesProfile(environment)) { environment.addActiveProfile(KUBERNETES_PROFILE); }/* w ww . j a v a 2 s . c om*/ } if (utils.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 'kuberntes' profile activation."); } } }