List of usage examples for org.springframework.core.env ConfigurableEnvironment containsProperty
boolean containsProperty(String key);
From source file:org.springframework.boot.context.initializer.VcapApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;/* ww w .j av a 2 s . c o m*/ } Properties properties = new Properties(); addWithPrefix(properties, getPropertiesFromApplication(environment), "vcap.application."); addWithPrefix(properties, getPropertiesFromServices(environment), "vcap.services."); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new PropertiesPropertySource("vcap", properties)); } else { propertySources.addFirst(new PropertiesPropertySource("vcap", properties)); } }
From source file:org.springframework.boot.context.listener.LoggingApplicationListener.java
/** * Initialize the logging system according to preferences expressed through the * {@link Environment} and the classpath. *//*from ww w . j av a 2 s . c om*/ protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) { if (this.parseArgs && this.springBootLogging == null) { if (environment.containsProperty("debug")) { this.springBootLogging = LogLevel.DEBUG; } if (environment.containsProperty("trace")) { this.springBootLogging = LogLevel.TRACE; } } boolean environmentChanged = false; for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING.entrySet()) { if (environment.containsProperty(mapping.getKey())) { System.setProperty(mapping.getValue(), environment.getProperty(mapping.getKey())); environmentChanged = true; } } LoggingSystem system = LoggingSystem.get(classLoader); if (environmentChanged) { // Re-initialize the defaults in case the Environment changed system.beforeInitialize(); } // User specified configuration if (environment.containsProperty("logging.config")) { String value = environment.getProperty("logging.config"); try { ResourceUtils.getURL(value).openStream().close(); system.initialize(value); return; } catch (Exception ex) { // Swallow exception and continue } this.logger.warn("Logging environment value '" + value + "' cannot be opened and will be ignored"); } system.initialize(); if (this.springBootLogging != null) { initializeLogLevel(system, this.springBootLogging); } }
From source file:org.springframework.boot.context.listener.VcapApplicationListener.java
@Override public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;//from www.java 2s . c o m } Properties properties = new Properties(); addWithPrefix(properties, getPropertiesFromApplication(environment), "vcap.application."); addWithPrefix(properties, getPropertiesFromServices(environment), "vcap.services."); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new PropertiesPropertySource("vcap", properties)); } else { propertySources.addFirst(new PropertiesPropertySource("vcap", properties)); } }
From source file:org.springframework.boot.logging.LoggingApplicationListener.java
private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) { if (this.parseArgs && this.springBootLogging == null) { if (environment.containsProperty("debug")) { this.springBootLogging = LogLevel.DEBUG; }/*w w w. j a v a 2 s. c o m*/ if (environment.containsProperty("trace")) { this.springBootLogging = LogLevel.TRACE; } } }
From source file:org.springframework.integration.samples.travel.Main.java
/** * @param args Not used./*from w ww .ja v a 2 s . c o m*/ */ public static void main(String... args) throws Exception { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); final ConfigurableEnvironment env = context.getEnvironment(); boolean mapQuestApiKeyDefined = env.containsProperty("mapquest.apikey"); if (mapQuestApiKeyDefined) { env.setActiveProfiles("mapquest"); } context.load("classpath:META-INF/spring/*.xml"); context.refresh(); final TravelGateway travelGateway = context.getBean("travelGateway", TravelGateway.class); final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration Travel App! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n========================================================="); System.out.println( "Please select the city, for which you would like to get traffic and weather information:"); for (City city : City.values()) { System.out.println(String.format("\t%s. %s", city.getId(), city.getName())); } System.out.println("\tq. Quit the application"); System.out.print("Enter your choice: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { System.out.println("Exiting application...bye."); break; } else { final Integer cityId = Integer.valueOf(input); final City city = City.getCityForId(cityId); final String weatherReply = travelGateway.getWeatherByCity(city); System.out.println("\n=========================================================" + "\n Weather:" + "\n========================================================="); System.out.println(weatherReply); if (mapQuestApiKeyDefined) { final String trafficReply = travelGateway.getTrafficByCity(city); System.out.println("\n=========================================================" + "\n Traffic:" + "\n========================================================="); System.out.println(trafficReply); } else { LOGGER.warn("Skipping Traffic Information call. Did you setup your MapQuest API Key? " + "e.g. by calling:\n\n $ mvn exec:java -Dmapquest.apikey=\"your_mapquest_api_key_url_decoded\""); } System.out.println("\n=========================================================" + "\n Done." + "\n========================================================="); System.out.print("Enter your choice: "); } } scanner.close(); context.close(); }