List of usage examples for org.springframework.core.env MutablePropertySources contains
@Override public boolean contains(String name)
From source file:io.spring.initializr.web.autoconfigure.CloudfoundryEnvironmentPostProcessor.java
private static void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null;/*from w w w .ja v a2 s . co m*/ if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } }
From source file:io.micrometer.spring.MetricsEnvironmentPostProcessor.java
private void addDefaultProperty(ConfigurableEnvironment environment, String name, String value) { MutablePropertySources sources = environment.getPropertySources(); Map<String, Object> map = null; if (sources.contains("defaultProperties")) { PropertySource<?> source = sources.get("defaultProperties"); if (source instanceof MapPropertySource) { map = ((MapPropertySource) source).getSource(); }//from www . j a v a 2 s. c om } else { map = new LinkedHashMap<>(); sources.addLast(new MapPropertySource("defaultProperties", map)); } if (map != null) { map.put(name, value); } }
From source file:com.example.journal.env.JournalEnvironmentPostProcessor.java
private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) { MapPropertySource target = null;// w ww . j a v a2s .c om if (propertySources.contains(PROPERTY_SOURCE_NAME)) { PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); if (source instanceof MapPropertySource) { target = (MapPropertySource) source; for (String key : map.keySet()) { if (!target.containsProperty(key)) { target.getSource().put(key, map.get(key)); } } } } if (target == null) { target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); } if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { propertySources.addLast(target); } }
From source file:org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.java
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) { 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 {/*from w w w .j ava 2 s .c o m*/ propertySources.addFirst(new PropertiesPropertySource("vcap", properties)); } } }
From source file:org.springframework.boot.cloudfoundry.VcapApplicationListener.java
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;//from w ww. jav a2s. 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.cloudfoundry.VcapEnvironmentPostProcessor.java
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;/* w ww . j ava 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.initializer.VcapApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;//from w w w . ja va 2 s . co 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.VcapApplicationListener.java
@Override public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.containsProperty(VCAP_APPLICATION) && !environment.containsProperty(VCAP_SERVICES)) { return;/* w ww. ja v 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.env.SpringApplicationJsonEnvironmentPostProcessor.java
private void addJsonPropertySource(ConfigurableEnvironment environment, PropertySource<?> source) { MutablePropertySources sources = environment.getPropertySources(); String name = findPropertySource(sources); if (sources.contains(name)) { sources.addBefore(name, source); } else {/*ww w .ja v a 2s .co m*/ sources.addFirst(source); } }
From source file:org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor.java
private String findPropertySource(MutablePropertySources sources) { if (ClassUtils.isPresent(SERVLET_ENVIRONMENT_CLASS, null) && sources.contains(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)) { return StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME; }/* w ww . ja va2 s.co m*/ return StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME; }