List of usage examples for org.springframework.core.env ConfigurableEnvironment acceptsProfiles
@Deprecated
boolean acceptsProfiles(String... profiles);
From source file:com.setronica.ucs.server.MessageServer.java
private static ClassPathXmlApplicationContext initApplication(String profile, DefaultListableBeanFactory parentBeanFactory) { ClassPathXmlApplicationContext applicationContext; if (parentBeanFactory != null) { //wrap BeanFactory inside ApplicationContext GenericApplicationContext parentContext = new GenericApplicationContext(parentBeanFactory); parentContext.refresh();/*from w w w .j av a 2 s .c o m*/ applicationContext = new ClassPathXmlApplicationContext(parentContext); } else { applicationContext = new ClassPathXmlApplicationContext(); } ConfigurableEnvironment environment = applicationContext.getEnvironment(); environment.setDefaultProfiles(profile); applicationContext.setConfigLocation("spring-application.xml"); // log active profile String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } for (String activeProfile : profiles) { if (environment.acceptsProfiles(activeProfile)) { logger.info("Profile " + activeProfile + " is active"); } } applicationContext.refresh(); return applicationContext; }
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 w w w . j a va 2 s .c om this.environment = environment; return ctx; }
From source file:org.jrecruiter.web.config.DefaultApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { final String profile = System.getProperty("jrecruiter-spring-profile"); if (profile == null) { LOGGER.info("System property 'jrecruiter-spring-profile' not set. Setting active profile to '{}'.", SpringContextMode.DemoContextConfiguration.getCode()); applicationContext.getEnvironment() .setActiveProfiles(SpringContextMode.DemoContextConfiguration.getCode()); } else {/* w w w .j a va 2 s .com*/ applicationContext.getEnvironment().setActiveProfiles(profile); } final ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (environment.acceptsProfiles("standalone")) { String tingHome = environment.getProperty(Apphome.APP_HOME_DIRECTORY); try { ResourcePropertySource source = new ResourcePropertySource( "file:" + tingHome + File.separator + SystemInformationUtils.JRECRUITER_CONFIG_FILENAME); environment.getPropertySources().addFirst(source); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Properties for standalone mode loaded"); } else { try { environment.getPropertySources() .addFirst(new ResourcePropertySource("classpath:jrecruiter-demo.properties")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Properties for demo mode loaded"); } final Boolean twitterEnabled = environment.getProperty("twitter.enabled", Boolean.class, Boolean.FALSE); if (twitterEnabled) { applicationContext.getEnvironment().addActiveProfile("twitter-enabled"); } System.out.println("::Twitter enabled: " + twitterEnabled); final Boolean mailEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); if (mailEnabled) { applicationContext.getEnvironment().addActiveProfile("mail-enabled"); } System.out.println("::Mail enabled: " + mailEnabled); final Boolean bitlyEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); if (bitlyEnabled) { applicationContext.getEnvironment().addActiveProfile("bitly-enabled"); } System.out.println("::Bitly enabled: " + bitlyEnabled); }
From source file:com.devnexus.ting.web.config.DefaultApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { final CloudEnvironment env = new CloudEnvironment(); if (env.getInstanceInfo() != null) { LOGGER.info("cloud API: " + env.getCloudApiUri()); applicationContext.getEnvironment().setActiveProfiles("cloud", SpringContextMode.DemoContextConfiguration.getCode()); } else {//from w ww . ja va2 s.c o m final String profile = System.getProperty("ting-spring-profile"); if (profile == null) { LOGGER.info("System property 'ting-spring-profile' not set. Setting active profile to '{}'.", SpringContextMode.DemoContextConfiguration.getCode()); applicationContext.getEnvironment() .setActiveProfiles(SpringContextMode.DemoContextConfiguration.getCode()); } else { applicationContext.getEnvironment().setActiveProfiles(profile); } } final ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (environment.acceptsProfiles(SpringProfile.STANDALONE)) { final String tingHome = environment.getProperty(Apphome.APP_HOME_DIRECTORY); final ResourcePropertySource propertySource; final String productionPropertySourceLocation = "file:" + tingHome + File.separator + SystemInformationUtils.TING_CONFIG_FILENAME; try { propertySource = new ResourcePropertySource(productionPropertySourceLocation); } catch (IOException e) { throw new IllegalStateException( "Unable to get ResourcePropertySource '" + productionPropertySourceLocation + "'", e); } environment.getPropertySources().addFirst(propertySource); LOGGER.info("Properties for standalone mode loaded [" + productionPropertySourceLocation + "]"); } else { final String demoPropertySourceLocation = "classpath:ting-demo.properties"; final ResourcePropertySource propertySource; try { propertySource = new ResourcePropertySource(demoPropertySourceLocation); } catch (IOException e) { throw new IllegalStateException( "Unable to get ResourcePropertySource '" + demoPropertySourceLocation + "'", e); } environment.getPropertySources().addFirst(propertySource); LOGGER.info("Properties for demo mode loaded [" + demoPropertySourceLocation + "]"); } final boolean mailEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); final boolean twitterEnabled = environment.getProperty("twitter.enabled", Boolean.class, Boolean.FALSE); final boolean websocketEnabled = environment.getProperty("websocket.enabled", Boolean.class, Boolean.FALSE); if (mailEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.MAIL_ENABLED); } if (twitterEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.TWITTER_ENABLED); } if (websocketEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.WEBSOCKET_ENABLED); } }
From source file:com.devnexus.ting.DefaultApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { final CloudEnvironment env = new CloudEnvironment(); if (env.getInstanceInfo() != null) { LOGGER.info("Running in the cloud - API: " + env.getCloudApiUri()); applicationContext.getEnvironment().setActiveProfiles(SpringProfile.CLOUD); } else {//from w w w . j a v a 2 s . co m final Apphome apphome = SystemInformationUtils.retrieveBasicSystemInformation(); SpringContextMode springContextMode; LOGGER.info("DevNexus Apphome: " + apphome); if (SystemInformationUtils.existsConfigFile(apphome.getAppHomePath())) { springContextMode = SpringContextMode.ProductionContextConfiguration; } else { springContextMode = SpringContextMode.DemoContextConfiguration; } applicationContext.getEnvironment().setActiveProfiles(springContextMode.getCode()); } final ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (environment.acceptsProfiles(SpringProfile.STANDALONE)) { final String tingHome = environment.getProperty(Apphome.APP_HOME_DIRECTORY); final PropertySource<?> propertySource; final YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader(); final String productionPropertySourceLocation; final Apphome apphome = SystemInformationUtils.retrieveBasicSystemInformation(); if (apphome.getAppHomeSource() == AppHomeSource.USER_DIRECTORY) { productionPropertySourceLocation = "file:" + apphome.getAppHomePath() + File.separator + SystemInformationUtils.TING_CONFIG_FILENAME; } else { productionPropertySourceLocation = "file:" + tingHome + File.separator + SystemInformationUtils.TING_CONFIG_FILENAME; } try { propertySource = yamlPropertySourceLoader.load("devnexus-standalone", new DefaultResourceLoader().getResource(productionPropertySourceLocation), null); } catch (IOException e) { throw new IllegalStateException( "Unable to get ResourcePropertySource '" + productionPropertySourceLocation + "'", e); } environment.getPropertySources().addFirst(propertySource); LOGGER.info("Properties for standalone mode loaded [" + productionPropertySourceLocation + "]."); } else { LOGGER.info("Using Properties for demo mode."); } final String emailProviderAsString = environment.getProperty("devnexus.mail.emailProvider"); final EmailProvider emailProvider = EmailProvider.valueOf(emailProviderAsString.trim().toUpperCase()); final boolean twitterEnabled = environment.getProperty("devnexus.twitter.enabled", Boolean.class, Boolean.FALSE); final boolean websocketEnabled = environment.getProperty("devnexus.websocket.enabled", Boolean.class, Boolean.FALSE); final boolean payPalEnabled = environment.containsProperty("PAYPAL_MODE"); LOGGER.info("Uses Settings:" + "\nEmail Provider: " + emailProvider + "\nTwitter Enabled: " + twitterEnabled + "\nPayPal Enabled: " + payPalEnabled + "\nWebsocket Enabled: " + websocketEnabled); if (EmailProvider.SENDGRID.equals(emailProvider)) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.SENDGRID_ENABLED); } else if (EmailProvider.SMTP.equals(emailProvider)) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.SMTP_ENABLED); } else if (EmailProvider.AMAZON_SES.equals(emailProvider)) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.AMAZON_SES_ENABLED); } else if (EmailProvider.NONE.equals(emailProvider)) { } else { throw new IllegalArgumentException("Unknown EmailProvider: " + emailProvider); } if (!EmailProvider.NONE.equals(emailProvider)) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.MAIL_ENABLED); } if (twitterEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.TWITTER_ENABLED); } if (websocketEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.WEBSOCKET_ENABLED); } if (payPalEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.PAYPAL_ENABLED); switch (environment.getProperty("PAYPAL_MODE")) { case "live": applicationContext.getEnvironment().addActiveProfile(SpringProfile.PAYPAL_LIVE); break; default: applicationContext.getEnvironment().addActiveProfile(SpringProfile.PAYPAL_SANDBOX); break; } } if (environment.getProperty("DEVELOPMENT_MODE", Boolean.class, Boolean.FALSE)) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.DEVELOPMENT_ENABLED); } }