List of usage examples for org.springframework.core.env MapPropertySource MapPropertySource
public MapPropertySource(String name, Map<String, Object> source)
From source file:org.springframework.cloud.config.server.environment.NativeEnvironmentRepository.java
private ConfigurableEnvironment getEnvironment(String profile) { ConfigurableEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("profiles", Collections.<String, Object>singletonMap("spring.profiles.active", profile))); return environment; }
From source file:org.springframework.cloud.dataflow.server.cloudfoundry.config.CloudFoundryEnvironmentPostProcessor.java
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (Boolean.valueOf(environment.getProperty(FEATURES_PREFIX + FeaturesProperties.TASKS_ENABLED))) { logger.warn(FEATURES_PREFIX + FeaturesProperties.TASKS_ENABLED + " has been set to true directly. " + "Be advised this is an EXPERIMENTAL feature, normally enabled via " + FEATURES_PREFIX + "experimental.tasksEnabled"); }// w ww .j a va 2 s . c o m Map<String, Object> propertiesToOverride = new HashMap<>(); boolean isTasksEnabled = Boolean .valueOf(environment.getProperty(FEATURES_PREFIX + "experimental.tasksEnabled")); if (isTasksEnabled) { propertiesToOverride.put(FEATURES_PREFIX + FeaturesProperties.TASKS_ENABLED, true); environment.getPropertySources() .addFirst(new MapPropertySource("CFDataflowServerProperties", propertiesToOverride)); } }
From source file:org.springframework.cloud.dataflow.server.config.DefaultEnvironmentPostProcessor.java
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { Map<String, Object> internalDefaults = new HashMap<>(); Map<String, Object> defaults = new HashMap<>(); MutablePropertySources existingPropertySources = environment.getPropertySources(); contributeDefaults(internalDefaults, serverDefaultsResource); contributeDefaults(defaults, serverResource); String defaultPropertiesKey = "defaultProperties"; if (!existingPropertySources.contains(defaultPropertiesKey) || existingPropertySources.get(defaultPropertiesKey) == null) { existingPropertySources.addLast(new MapPropertySource(defaultPropertiesKey, internalDefaults)); existingPropertySources.addLast(new MapPropertySource(defaultPropertiesKey, defaults)); } else {/*w ww. j av a 2 s. co m*/ PropertySource<?> propertySource = existingPropertySources.get(defaultPropertiesKey); @SuppressWarnings("unchecked") Map<String, Object> mapOfProperties = Map.class.cast(propertySource.getSource()); for (String k : internalDefaults.keySet()) { Set<String> setOfPropertyKeys = mapOfProperties.keySet(); if (!setOfPropertyKeys.contains(k)) { mapOfProperties.put(k, internalDefaults.get(k)); logger.debug(k + '=' + internalDefaults.get(k)); } } for (String k : defaults.keySet()) { Set<String> setOfPropertyKeys = mapOfProperties.keySet(); if (!setOfPropertyKeys.contains(k)) { mapOfProperties.put(k, defaults.get(k)); logger.debug(k + '=' + defaults.get(k)); } } } }
From source file:org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader.java
@Override protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { int availableServerSocket = SocketUtils.findAvailableTcpPort(5678); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); if (LOGGER.isInfoEnabled()) { LOGGER.info("Available Server Socket: " + availableServerSocket); }//from w ww. j av a 2s. c o m final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); super.loadBeanDefinitions(context, mergedConfig); }
From source file:org.springframework.test.context.support.TestPropertySourceUtils.java
/** * Add the given <em>inlined properties</em> (in the form of <em>key-value</em> * pairs) to the supplied {@link ConfigurableEnvironment environment}. * <p>All key-value pairs will be added to the {@code Environment} as a * single {@link MapPropertySource} with the highest precedence. * <p>For details on the parsing of <em>inlined properties</em>, consult the * Javadoc for {@link #convertInlinedPropertiesToMap}. * @param environment the environment to update; never {@code null} * @param inlinedProperties the inlined properties to add to the environment; * potentially empty but never {@code null} * @since 4.1.5/* w ww. j a v a 2 s . c o m*/ * @see MapPropertySource * @see #INLINED_PROPERTIES_PROPERTY_SOURCE_NAME * @see TestPropertySource#properties * @see #convertInlinedPropertiesToMap */ public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties) { Assert.notNull(environment, "'environment' must not be null"); Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null"); if (!ObjectUtils.isEmpty(inlinedProperties)) { if (logger.isDebugEnabled()) { logger.debug("Adding inlined properties to environment: " + ObjectUtils.nullSafeToString(inlinedProperties)); } MapPropertySource ps = (MapPropertySource) environment.getPropertySources() .get(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); if (ps == null) { ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME, new LinkedHashMap<>()); environment.getPropertySources().addFirst(ps); } ps.getSource().putAll(convertInlinedPropertiesToMap(inlinedProperties)); } }
From source file:org.springframework.yarn.boot.support.YarnBootClientApplicationListener.java
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { MutablePropertySources propertySources = event.getEnvironment().getPropertySources(); if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { if (log.isDebugEnabled()) { log.debug("Adding afterCommandLineArgs property source after " + CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME); }//from w w w. j a va2s. c o m propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new MapPropertySource("afterCommandLineArgs", propertySourceMap)); } else { if (log.isDebugEnabled()) { log.debug("Adding afterCommandLineArgs property source as first"); } propertySources.addFirst(new MapPropertySource("afterCommandLineArgs", propertySourceMap)); } }