org.springframework.core.env.MapPropertySource Java Examples
The following examples show how to use
org.springframework.core.env.MapPropertySource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyndesisCommand.java From syndesis with Apache License 2.0 | 6 votes |
private AbstractApplicationContext createContext() { final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); final YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader(); final List<PropertySource<?>> yamlPropertySources; try { yamlPropertySources = propertySourceLoader.load(name, context.getResource("classpath:" + name + ".yml")); } catch (final IOException e) { throw new IllegalStateException(e); } final StandardEnvironment environment = new StandardEnvironment(); final MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new MapPropertySource("parameters", parameters)); yamlPropertySources.forEach(propertySources::addLast); context.setEnvironment(environment); final String packageName = getClass().getPackage().getName(); context.scan(packageName); context.refresh(); return context; }
Example #2
Source File: BootstrapApplicationListener.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
private void mergeDefaultProperties(MutablePropertySources environment, MutablePropertySources bootstrap) { String name = DEFAULT_PROPERTIES; if (bootstrap.contains(name)) { PropertySource<?> source = bootstrap.get(name); if (!environment.contains(name)) { environment.addLast(source); } else { PropertySource<?> target = environment.get(name); if (target instanceof MapPropertySource && target != source && source instanceof MapPropertySource) { Map<String, Object> targetMap = ((MapPropertySource) target) .getSource(); Map<String, Object> map = ((MapPropertySource) source).getSource(); for (String key : map.keySet()) { if (!target.containsProperty(key)) { targetMap.put(key, map.get(key)); } } } } } mergeAdditionalPropertySources(environment, bootstrap); }
Example #3
Source File: DependencyEnvironmentPostProcessor.java From spring-cloud-zookeeper with Apache License 2.0 | 6 votes |
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { String appName = environment.getProperty("spring.application.name"); if (StringUtils.hasText(appName) && !appName.contains("/")) { String prefix = environment.getProperty("spring.cloud.zookeeper.prefix"); if (StringUtils.hasText(prefix)) { StringBuilder prefixedName = new StringBuilder(); if (!prefix.startsWith("/")) { prefixedName.append("/"); } prefixedName.append(prefix); if (!prefix.endsWith("/")) { prefixedName.append("/"); } prefixedName.append(appName); MapPropertySource propertySource = new MapPropertySource( "zookeeperDependencyEnvironment", Collections.singletonMap("spring.application.name", (Object) prefixedName.toString())); environment.getPropertySources().addFirst(propertySource); } } }
Example #4
Source File: JsonPropertyContextInitializer.java From tutorials with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public void initialize(ConfigurableApplicationContext configurableApplicationContext) { try { Resource resource = configurableApplicationContext.getResource("classpath:configprops.json"); Map readValue = new ObjectMapper().readValue(resource.getInputStream(), Map.class); Set<Map.Entry> set = readValue.entrySet(); List<MapPropertySource> propertySources = convertEntrySet(set, Optional.empty()); for (PropertySource propertySource : propertySources) { configurableApplicationContext.getEnvironment() .getPropertySources() .addFirst(propertySource); } } catch (IOException e) { throw new RuntimeException(e); } }
Example #5
Source File: EurekaClientConfigBeanTests.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Test public void serviceUrlWithCompositePropertySource() { CompositePropertySource source = new CompositePropertySource("composite"); this.context.getEnvironment().getPropertySources().addFirst(source); source.addPropertySource(new MapPropertySource("config", Collections.<String, Object>singletonMap( "eureka.client.serviceUrl.defaultZone", "https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com"))); this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(EurekaClientConfigBean.class).getServiceUrl() .toString()).isEqualTo( "{defaultZone=https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com}"); assertThat(getEurekaServiceUrlsForDefaultZone()).isEqualTo( "[https://example.com/, https://example2.com/, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com/]"); }
Example #6
Source File: TestBootstrapConfiguration.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Bean public ApplicationContextInitializer<ConfigurableApplicationContext> customInitializer() { return new ApplicationContextInitializer<ConfigurableApplicationContext>() { @Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); environment.getPropertySources() .addLast(new MapPropertySource("customProperties", Collections.<String, Object>singletonMap("custom.foo", environment.resolvePlaceholders( "${spring.application.name:bar}")))); } }; }
Example #7
Source File: ServiceInfoPropertySourceAdapter.java From spring-cloud-services-connector with Apache License 2.0 | 6 votes |
private void conditionallyExcludeRabbitAutoConfiguration() { if (appIsBoundToRabbitMQ()) { return; } Map<String, Object> properties = new LinkedHashMap<>(); String existingExcludes = environment.getProperty(SPRING_AUTOCONFIGURE_EXCLUDE); if (existingExcludes == null) { properties.put(SPRING_AUTOCONFIGURE_EXCLUDE, RABBIT_AUTOCONFIG_CLASS); } else if (!existingExcludes.contains(RABBIT_AUTOCONFIG_CLASS)) { properties.put(SPRING_AUTOCONFIGURE_EXCLUDE, RABBIT_AUTOCONFIG_CLASS + "," + existingExcludes); } PropertySource<?> propertySource = new MapPropertySource("springCloudServicesRabbitAutoconfigExcluder", properties); environment.getPropertySources().addFirst(propertySource); }
Example #8
Source File: KafkaBinderEnvironmentPostProcessor.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (!environment.getPropertySources().contains(KAFKA_BINDER_DEFAULT_PROPERTIES)) { Map<String, Object> kafkaBinderDefaultProperties = new HashMap<>(); kafkaBinderDefaultProperties.put("logging.level.org.I0Itec.zkclient", "ERROR"); kafkaBinderDefaultProperties.put("logging.level.kafka.server.KafkaConfig", "ERROR"); kafkaBinderDefaultProperties .put("logging.level.kafka.admin.AdminClient.AdminConfig", "ERROR"); kafkaBinderDefaultProperties.put(SPRING_KAFKA_PRODUCER_KEY_SERIALIZER, ByteArraySerializer.class.getName()); kafkaBinderDefaultProperties.put(SPRING_KAFKA_PRODUCER_VALUE_SERIALIZER, ByteArraySerializer.class.getName()); kafkaBinderDefaultProperties.put(SPRING_KAFKA_CONSUMER_KEY_DESERIALIZER, ByteArrayDeserializer.class.getName()); kafkaBinderDefaultProperties.put(SPRING_KAFKA_CONSUMER_VALUE_DESERIALIZER, ByteArrayDeserializer.class.getName()); environment.getPropertySources().addLast(new MapPropertySource( KAFKA_BINDER_DEFAULT_PROPERTIES, kafkaBinderDefaultProperties)); } }
Example #9
Source File: BootstrapConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Override public PropertySource<?> locate(Environment environment) { if (this.name != null) { then(this.name) .isEqualTo(environment.getProperty("spring.application.name")); } if (this.fail) { throw new RuntimeException("Planned"); } CompositePropertySource compositePropertySource = new CompositePropertySource( "listTestBootstrap"); compositePropertySource.addFirstPropertySource( new MapPropertySource("testBootstrap1", MAP1)); compositePropertySource.addFirstPropertySource( new MapPropertySource("testBootstrap2", MAP2)); return compositePropertySource; }
Example #10
Source File: BinderDubboConfigBinder.java From dubbo-spring-boot-project with Apache License 2.0 | 6 votes |
@Override public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) { Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties)); // Converts ConfigurationPropertySources Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources); // Wrap Bindable from DubboConfig instance Bindable bindable = Bindable.ofInstance(configurationBean); Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); // Get BindHandler BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields); // Bind binder.bind("", bindable, bindHandler); }
Example #11
Source File: AmazonRdsInstanceConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void configureBean_withDefaultClientSpecifiedAndNoReadReplicaWithExpressions_configuresFactoryBeanWithoutReadReplicaAndResolvedExpressions() throws Exception { // @checkstyle:on // Arrange this.context = new AnnotationConfigApplicationContext(); HashMap<String, Object> propertySourceProperties = new HashMap<>(); propertySourceProperties.put("dbInstanceIdentifier", "test"); propertySourceProperties.put("password", "secret"); propertySourceProperties.put("username", "admin"); this.context.getEnvironment().getPropertySources() .addLast(new MapPropertySource("test", propertySourceProperties)); // Act this.context .register(ApplicationConfigurationWithoutReadReplicaAndExpressions.class); this.context.refresh(); // Assert assertThat(this.context.getBean(DataSource.class)).isNotNull(); assertThat(this.context.getBean(AmazonRdsDataSourceFactoryBean.class)) .isNotNull(); }
Example #12
Source File: ContextFunctionCatalogInitializerTests.java From spring-cloud-function with Apache License 2.0 | 6 votes |
private void create(ApplicationContextInitializer<GenericApplicationContext>[] types, String... props) { this.context = new GenericApplicationContext(); Map<String, Object> map = new HashMap<>(); for (String prop : props) { String[] array = StringUtils.delimitedListToStringArray(prop, "="); String key = array[0]; String value = array.length > 1 ? array[1] : ""; map.put(key, value); } if (!map.isEmpty()) { this.context.getEnvironment().getPropertySources() .addFirst(new MapPropertySource("testProperties", map)); } for (ApplicationContextInitializer<GenericApplicationContext> type : types) { type.initialize(this.context); } new ContextFunctionCatalogInitializer.ContextFunctionCatalogBeanRegistrar( this.context).postProcessBeanDefinitionRegistry(this.context); this.context.refresh(); this.catalog = this.context.getBean(FunctionCatalog.class); this.inspector = this.context.getBean(FunctionInspector.class); }
Example #13
Source File: SettingsServiceTestCase.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
@Test public void migrateEnvKeys_keyChainPrecedence2() { Map<String, String> keyMaps = new LinkedHashMap<>(); keyMaps.put("bla", "bla2"); keyMaps.put("bla2", "bla3"); keyMaps.put("bla3", "bla4"); Map<String, Object> migrated = new LinkedHashMap<>(); // higher precedence starts later in the chain order SettingsService.migratePropertySourceKeys(keyMaps, new MapPropertySource("migrated-properties", ImmutableMap.of("bla3", "1")), migrated); SettingsService.migratePropertySourceKeys(keyMaps, new MapPropertySource("migrated-properties", ImmutableMap.of("bla", "3")), migrated); assertThat(migrated).containsOnly(entry("bla2", "3"), entry("bla3", "3"), entry("bla4", "1")); }
Example #14
Source File: GsRemotingTest.java From astrix with Apache License 2.0 | 6 votes |
@Test public void broadcastedServiceInvocationThrowServiceUnavailableWhenProxyIsContextIsClosed() throws Exception { AnnotationConfigApplicationContext pingServer = autoClosables.add(new AnnotationConfigApplicationContext()); pingServer.register(PingAppConfig.class); pingServer.getEnvironment().getPropertySources().addFirst(new MapPropertySource("props", new HashMap<String, Object>() {{ put("serviceRegistryUri", serviceRegistry.getServiceUri()); }})); pingServer.refresh(); AstrixContext context = autoClosables.add( new TestAstrixConfigurer().registerApiProvider(PingApi.class) .set(AstrixSettings.SERVICE_REGISTRY_URI, serviceRegistry.getServiceUri()) .set(AstrixSettings.BEAN_BIND_ATTEMPT_INTERVAL, 200) .configure()); Ping ping = context.waitForBean(Ping.class, 10000); assertEquals("foo", ping.broadcastPing("foo").get(0)); context.destroy(); assertThrows(() -> ping.broadcastPing("foo"), ServiceUnavailableException.class); }
Example #15
Source File: EnvironmentVaultConfigurationUnitTests.java From spring-vault with Apache License 2.0 | 6 votes |
@Test void shouldConfigureSsl() { Map<String, Object> map = new HashMap<String, Object>(); map.put("vault.ssl.key-store", "classpath:certificate.json"); map.put("vault.ssl.trust-store", "classpath:certificate.json"); MapPropertySource propertySource = new MapPropertySource("shouldConfigureSsl", map); this.configurableEnvironment.getPropertySources().addFirst(propertySource); SslConfiguration sslConfiguration = this.configuration.sslConfiguration(); assertThat(sslConfiguration.getKeyStore()).isInstanceOf(ClassPathResource.class); assertThat(sslConfiguration.getKeyStorePassword()).isEqualTo("key store password"); assertThat(sslConfiguration.getTrustStore()).isInstanceOf(ClassPathResource.class); assertThat(sslConfiguration.getTrustStorePassword()).isEqualTo("trust store password"); this.configurableEnvironment.getPropertySources().remove(propertySource.getName()); }
Example #16
Source File: EurekaServiceConnector.java From spring-cloud-services-connector with Apache License 2.0 | 5 votes |
@Override protected PropertySource<?> toPropertySource(EurekaServiceInfo eurekaServiceInfo) { Map<String, Object> map = new LinkedHashMap<>(); map.put(EUREKA_CLIENT + "serviceUrl.defaultZone", eurekaServiceInfo.getUri() + EUREKA_API_PREFIX); map.put(EUREKA_CLIENT + "region", DEFAULT_REGION); map.put(EUREKA_CLIENT_OAUTH2 + "clientId", eurekaServiceInfo.getClientId()); map.put(EUREKA_CLIENT_OAUTH2 + "clientSecret", eurekaServiceInfo.getClientSecret()); map.put(EUREKA_CLIENT_OAUTH2 + "accessTokenUri", eurekaServiceInfo.getAccessTokenUri()); return new MapPropertySource(PROPERTY_SOURCE_NAME, map); }
Example #17
Source File: QueueMessageHandlerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void receiveMessage_methodAnnotatedWithSqsListenerContainingPlaceholder_methodInvokedOnResolvedPlaceholder() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getEnvironment().getPropertySources() .addLast(new MapPropertySource("test", Collections.singletonMap("custom.queueName", "resolvedQueue"))); applicationContext.registerSingleton("ppc", PropertySourcesPlaceholderConfigurer.class); applicationContext.registerSingleton( "incomingMessageHandlerWithMultipleQueueNames", IncomingMessageHandlerWithPlaceholderName.class); applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class); applicationContext.refresh(); QueueMessageHandler queueMessageHandler = applicationContext .getBean(QueueMessageHandler.class); // Act queueMessageHandler.handleMessage(MessageBuilder .withPayload("Hello from resolved queue!") .setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "resolvedQueue") .build()); // Assert IncomingMessageHandlerWithPlaceholderName incomingMessageHandler = applicationContext .getBean(IncomingMessageHandlerWithPlaceholderName.class); assertThat(incomingMessageHandler.getLastReceivedMessage()) .isEqualTo("Hello from resolved queue!"); }
Example #18
Source File: FooConfigurationTest.java From spring-test-examples with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = NoSuchBeanDefinitionException.class) public void testFooCreatePropertyFalse() { context.getEnvironment().getPropertySources().addLast( new MapPropertySource("test", Collections.singletonMap("foo.create", "false")) ); context.register(FooConfiguration.class); context.refresh(); assertNotNull(context.getBean(Foo.class)); }
Example #19
Source File: FlowableLiquibaseEnvironmentPostProcessor.java From syncope with Apache License 2.0 | 5 votes |
@Override public void postProcessEnvironment(final ConfigurableEnvironment env, final SpringApplication app) { if (!env.containsProperty(LIQUIBASE_PROPERTY)) { env.getPropertySources().addLast( new MapPropertySource("flowable-liquibase-override", Map.of(LIQUIBASE_PROPERTY, false))); } }
Example #20
Source File: KafkaStreamsBinderSupportAutoConfiguration.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@Bean @ConfigurationProperties(prefix = "spring.cloud.stream.kafka.streams.binder") public KafkaStreamsBinderConfigurationProperties binderConfigurationProperties( KafkaProperties kafkaProperties, ConfigurableEnvironment environment, BindingServiceProperties properties, ConfigurableApplicationContext context) throws Exception { final Map<String, BinderConfiguration> binderConfigurations = getBinderConfigurations( properties); for (Map.Entry<String, BinderConfiguration> entry : binderConfigurations .entrySet()) { final BinderConfiguration binderConfiguration = entry.getValue(); final String binderType = binderConfiguration.getBinderType(); if (binderType != null && (binderType.equals(KSTREAM_BINDER_TYPE) || binderType.equals(KTABLE_BINDER_TYPE) || binderType.equals(GLOBALKTABLE_BINDER_TYPE))) { Map<String, Object> binderProperties = new HashMap<>(); this.flatten(null, binderConfiguration.getProperties(), binderProperties); environment.getPropertySources().addFirst( new MapPropertySource(entry.getKey() + "-kafkaStreamsBinderEnv", binderProperties)); Binder binder = new Binder(ConfigurationPropertySources.get(environment), new PropertySourcesPlaceholdersResolver(environment), IntegrationUtils.getConversionService(context.getBeanFactory()), null); final Constructor<KafkaStreamsBinderConfigurationProperties> kafkaStreamsBinderConfigurationPropertiesConstructor = ReflectionUtils.accessibleConstructor(KafkaStreamsBinderConfigurationProperties.class, KafkaProperties.class); final KafkaStreamsBinderConfigurationProperties kafkaStreamsBinderConfigurationProperties = BeanUtils.instantiateClass(kafkaStreamsBinderConfigurationPropertiesConstructor, kafkaProperties); final BindResult<KafkaStreamsBinderConfigurationProperties> bind = binder.bind("spring.cloud.stream.kafka.streams.binder", Bindable.ofInstance(kafkaStreamsBinderConfigurationProperties)); context.getBeanFactory().registerSingleton( entry.getKey() + "-KafkaStreamsBinderConfigurationProperties", bind.get()); } } return new KafkaStreamsBinderConfigurationProperties(kafkaProperties); }
Example #21
Source File: DistCpConfiguration.java From circus-train with Apache License 2.0 | 5 votes |
@PostConstruct public void postConstruct() { Map<String, Object> properties = ImmutableMap .<String, Object>builder() .put("copier-options.file-attribute", "replication, blocksize, user, group, permission, checksumtype, xattr") .put("copier-options.preserve-raw-xattrs", true) .build(); env.getPropertySources().addLast(new MapPropertySource("distCpProperties", properties)); }
Example #22
Source File: BootstrapOrderingCustomOverrideSystemPropertiesIntegrationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Override public Collection<PropertySource<?>> locateCollection(Environment environment) { ArrayList<PropertySource<?>> sources = new ArrayList<>(); sources.add(new MapPropertySource("testBootstrap1", singletonMap("key1", "value1"))); sources.add(new MapPropertySource("testBootstrap2", singletonMap("key2", "value2"))); Map<String, Object> map = new HashMap<>(); map.put("key3", "value3"); map.put("spring.cloud.config.override-system-properties", "false"); sources.add(new MapPropertySource("testBootstrap3", map)); return sources; }
Example #23
Source File: SpringJ2CacheConfigUtil.java From J2Cache with Apache License 2.0 | 5 votes |
/** * 从spring环境变量中查找j2cache配置 * @param environment configuration * @return j2cache config instance */ public final static J2CacheConfig initFromConfig(StandardEnvironment environment){ J2CacheConfig config = new J2CacheConfig(); config.setSerialization(environment.getProperty("j2cache.serialization")); config.setBroadcast(environment.getProperty("j2cache.broadcast")); config.setL1CacheName(environment.getProperty("j2cache.L1.provider_class")); config.setL2CacheName(environment.getProperty("j2cache.L2.provider_class")); config.setSyncTtlToRedis(!"false".equalsIgnoreCase(environment.getProperty("j2cache.sync_ttl_to_redis"))); config.setDefaultCacheNullObject("true".equalsIgnoreCase(environment.getProperty("j2cache.default_cache_null_object"))); String l2_config_section = environment.getProperty("j2cache.L2.config_section"); if (l2_config_section == null || Objects.equals(l2_config_section.trim(),"")) l2_config_section = config.getL2CacheName(); final String l2_section = l2_config_section; environment.getPropertySources().forEach(a -> { if(a instanceof MapPropertySource) { MapPropertySource c = (MapPropertySource) a; c.getSource().forEach((k,v) -> { String key = k; if (key.startsWith(config.getBroadcast() + ".")) { config.getBroadcastProperties().setProperty(key.substring((config.getBroadcast() + ".").length()), environment.getProperty(key)); } if (key.startsWith(config.getL1CacheName() + ".")) { config.getL1CacheProperties().setProperty(key.substring((config.getL1CacheName() + ".").length()), environment.getProperty(key)); } if (key.startsWith(l2_section + ".")) { config.getL2CacheProperties().setProperty(key.substring((l2_section + ".").length()), environment.getProperty(key)); } }); } }); return config; }
Example #24
Source File: ConfigServerServiceConnector.java From spring-cloud-services-connector with Apache License 2.0 | 5 votes |
@Override protected PropertySource<?> toPropertySource(ConfigServerServiceInfo serviceInfo) { Map<String, Object> properties = new LinkedHashMap<>(); properties.put(SPRING_CLOUD_CONFIG_URI, serviceInfo.getUri()); properties.put(SPRING_CLOUD_CONFIG_OAUTH2_CLIENT_CLIENT_ID, serviceInfo.getClientId()); properties.put(SPRING_CLOUD_CONFIG_OAUTH2_CLIENT_CLIENT_SECRET, serviceInfo.getClientSecret()); properties.put(SPRING_CLOUD_CONFIG_OAUTH2_CLIENT_ACCESS_TOKEN_URI, serviceInfo.getAccessTokenUri()); return new MapPropertySource(PROPERTY_SOURCE_NAME, properties); }
Example #25
Source File: TestBinderEnvironmentPostProcessor.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { Map<String, Object> propertiesToAdd = new HashMap<>(); propertiesToAdd.put("spring.cloud.stream.binders.test.defaultCandidate", "false"); environment.getPropertySources() .addLast(new MapPropertySource("testBinderConfig", propertiesToAdd)); }
Example #26
Source File: SecretsPropertySourceLocator.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
private MapPropertySource getKubernetesPropertySourceForSingleSecret( ConfigurableEnvironment environment, SecretsConfigProperties.NormalizedSource normalizedSource) { String configurationTarget = this.properties.getConfigurationTarget(); return new SecretsPropertySource(this.client, environment, getApplicationName(environment, normalizedSource.getName(), configurationTarget), getApplicationNamespace(this.client, normalizedSource.getNamespace(), configurationTarget), normalizedSource.getLabels()); }
Example #27
Source File: ExtendPropertySourcesRunListener.java From thinking-in-spring-boot-samples with Apache License 2.0 | 5 votes |
@Override public void contextPrepared(ConfigurableApplicationContext context) { // 从 ConfigurableApplicationContext 获取 ConfigurableEnvironment ConfigurableEnvironment environment = context.getEnvironment(); Map<String, Object> source = new HashMap<>(); // 内部化配置设置 user.name 属性 source.put("user.name", "mercyblitz 2018"); MapPropertySource mapPropertySource = new MapPropertySource("contextPrepared", source); environment.getPropertySources().addFirst(mapPropertySource); }
Example #28
Source File: ContextRefresher.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
private StandardEnvironment copyEnvironment(ConfigurableEnvironment input) { StandardEnvironment environment = new StandardEnvironment(); MutablePropertySources capturedPropertySources = environment.getPropertySources(); // Only copy the default property source(s) and the profiles over from the main // environment (everything else should be pristine, just like it was on startup). for (String name : DEFAULT_PROPERTY_SOURCES) { if (input.getPropertySources().contains(name)) { if (capturedPropertySources.contains(name)) { capturedPropertySources.replace(name, input.getPropertySources().get(name)); } else { capturedPropertySources.addLast(input.getPropertySources().get(name)); } } } environment.setActiveProfiles(input.getActiveProfiles()); environment.setDefaultProfiles(input.getDefaultProfiles()); Map<String, Object> map = new HashMap<String, Object>(); map.put("spring.jmx.enabled", false); map.put("spring.main.sources", ""); // gh-678 without this apps with this property set to REACTIVE or SERVLET fail map.put("spring.main.web-application-type", "NONE"); capturedPropertySources .addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map)); return environment; }
Example #29
Source File: EvalTagTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void environmentAccess() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("key.foo", "value.foo"); GenericApplicationContext wac = (GenericApplicationContext) context.getRequest().getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); wac.getEnvironment().getPropertySources().addFirst(new MapPropertySource("mapSource", map)); wac.getDefaultListableBeanFactory().registerSingleton("bean2", context.getRequest().getAttribute("bean")); tag.setExpression("@environment['key.foo']"); int action = tag.doStartTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, action); action = tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, action); assertEquals("value.foo", ((MockHttpServletResponse) context.getResponse()).getContentAsString()); }
Example #30
Source File: EmbeddedCassandraContextCustomizer.java From embedded-cassandra with Apache License 2.0 | 5 votes |
@Override public Cassandra get() { Cassandra cassandra = create(); cassandra.start(); if (this.exposeProperties) { Map<String, Object> properties = new LinkedHashMap<>(); InetAddress address = cassandra.getAddress(); if (address != null) { properties.put("embedded.cassandra.address", address.getHostAddress()); } int port = cassandra.getPort(); if (port != -1) { properties.put("embedded.cassandra.port", port); } int sslPort = cassandra.getSslPort(); if (sslPort != -1) { properties.put("embedded.cassandra.ssl-port", sslPort); } int rpcPort = cassandra.getRpcPort(); if (rpcPort != -1) { properties.put("embedded.cassandra.rpc-port", rpcPort); } properties.put("embedded.cassandra.version", cassandra.getVersion().toString()); this.context.getEnvironment().getPropertySources().addFirst( new MapPropertySource("@EmbeddedCassandra", properties)); } return cassandra; }