本文整理了Java中org.springframework.core.env.PropertySource.getSource()
方法的一些代码示例,展示了PropertySource.getSource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PropertySource.getSource()
方法的具体详情如下:
包路径:org.springframework.core.env.PropertySource
类名称:PropertySource
方法名:getSource
[英]Return the underlying source object for this PropertySource.
[中]返回此PropertySource的基础源对象。
代码示例来源:origin: org.springframework.boot/spring-boot
private static PropertySource<?> getRootSource(PropertySource<?> source) {
while (source.getSource() != null
&& source.getSource() instanceof PropertySource) {
source = (PropertySource<?>) source.getSource();
}
return source;
}
代码示例来源:origin: org.springframework.boot/spring-boot
private static Function<ConfigurationPropertyName, ConfigurationPropertyState> getContainsDescendantOfForSource(
PropertySource<?> source) {
if (source.getSource() instanceof Random) {
return SpringConfigurationPropertySource::containsDescendantOfForRandom;
}
return null;
}
代码示例来源:origin: org.springframework.boot/spring-boot
private static Stream<PropertySource<?>> flatten(PropertySource<?> source) {
if (source.getSource() instanceof ConfigurableEnvironment) {
return streamPropertySources(
((ConfigurableEnvironment) source.getSource()).getPropertySources());
}
return Stream.of(source);
}
代码示例来源:origin: org.springframework.boot/spring-boot
private static boolean isFullEnumerable(PropertySource<?> source) {
PropertySource<?> rootSource = getRootSource(source);
if (rootSource.getSource() instanceof Map) {
// Check we're not security restricted
try {
((Map<?, ?>) rootSource.getSource()).size();
}
catch (UnsupportedOperationException ex) {
return false;
}
}
return (source instanceof EnumerablePropertySource);
}
代码示例来源:origin: apache/incubator-dubbo
private Map<String, String> getConfigurations(String key, Environment environment) {
Object rawProperties = environment.getProperty(key, Object.class);
Map<String, String> externalProperties = new HashMap<>();
try {
if (rawProperties instanceof Map) {
externalProperties.putAll((Map<String, String>) rawProperties);
} else if (rawProperties instanceof String) {
externalProperties.putAll(ConfigurationUtils.parseProperties((String) rawProperties));
}
if (environment instanceof ConfigurableEnvironment && externalProperties.isEmpty()) {
ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment;
PropertySource propertySource = configurableEnvironment.getPropertySources().get(key);
if (propertySource != null) {
Object source = propertySource.getSource();
if (source instanceof Map) {
((Map<String, Object>) source).forEach((k, v) -> {
externalProperties.put(k, (String) v);
});
}
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
return externalProperties;
}
代码示例来源:origin: apache/incubator-dubbo
private Map<String, String> getConfigurations(String key, Environment environment) {
Object rawProperties = environment.getProperty(key, Object.class);
Map<String, String> externalProperties = new HashMap<>();
try {
if (rawProperties instanceof Map) {
externalProperties.putAll((Map<String, String>) rawProperties);
} else if (rawProperties instanceof String) {
externalProperties.putAll(ConfigurationUtils.parseProperties((String) rawProperties));
}
if (environment instanceof ConfigurableEnvironment && externalProperties.isEmpty()) {
ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment;
PropertySource propertySource = configurableEnvironment.getPropertySources().get(key);
if (propertySource != null) {
Object source = propertySource.getSource();
if (source instanceof Map) {
((Map<String, Object>) source).forEach((k, v) -> {
externalProperties.put(k, (String) v);
});
}
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
return externalProperties;
}
代码示例来源:origin: spring-cloud/spring-cloud-config
private Map<?, ?> getMap(org.springframework.core.env.PropertySource<?> source) {
Map<Object, Object> map = new LinkedHashMap<>();
Map<?, ?> input = (Map<?, ?>) source.getSource();
for (Object key : input.keySet()) {
// Spring Boot wraps the property values in an "origin" detector, so we need
// to extract the string values
map.put(key, source.getProperty(key.toString()));
}
return map;
}
代码示例来源:origin: org.springframework.boot/spring-boot
@SuppressWarnings("unchecked")
private void replacePropertySource(ConfigurableEnvironment environment,
String sourceName, PropertySource<?> propertySource) {
Map<String, Object> originalSource = (Map<String, Object>) propertySource
.getSource();
SystemEnvironmentPropertySource source = new OriginAwareSystemEnvironmentPropertySource(
sourceName, originalSource);
environment.getPropertySources().replace(sourceName, source);
}
代码示例来源:origin: org.springframework.boot/spring-boot
@SuppressWarnings("unchecked")
private void setPortProperty(ConfigurableEnvironment environment, String propertyName,
int port) {
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get("server.ports");
if (source == null) {
source = new MapPropertySource("server.ports", new HashMap<>());
sources.addFirst(source);
}
((Map<String, Object>) source.getSource()).put(propertyName, port);
}
代码示例来源:origin: org.springframework.boot/spring-boot
private ConfigurationPropertySource fetchNext() {
if (this.next == null) {
if (this.iterators.isEmpty()) {
return null;
}
if (!this.iterators.peek().hasNext()) {
this.iterators.pop();
return fetchNext();
}
PropertySource<?> candidate = this.iterators.peek().next();
if (candidate.getSource() instanceof ConfigurableEnvironment) {
push((ConfigurableEnvironment) candidate.getSource());
return fetchNext();
}
if (isIgnored(candidate)) {
return fetchNext();
}
this.next = this.adapter.apply(candidate);
}
return this.next;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("serial")
public void collectionsOperations() {
Map<String, Object> map1 = new HashMap<String, Object>() {{ put("a", "b"); }};
Map<String, Object> map2 = new HashMap<String, Object>() {{ put("c", "d"); }};
PropertySource<?> ps1 = new MapPropertySource("ps1", map1);
ps1.getSource();
List<PropertySource<?>> propertySources = new ArrayList<>();
assertThat(propertySources.add(ps1), equalTo(true));
assertThat(propertySources.contains(ps1), is(true));
assertThat(propertySources.contains(PropertySource.named("ps1")), is(true));
PropertySource<?> ps1replacement = new MapPropertySource("ps1", map2); // notice - different map
assertThat(propertySources.add(ps1replacement), is(true)); // true because linkedlist allows duplicates
assertThat(propertySources.size(), is(2));
assertThat(propertySources.remove(PropertySource.named("ps1")), is(true));
assertThat(propertySources.size(), is(1));
assertThat(propertySources.remove(PropertySource.named("ps1")), is(true));
assertThat(propertySources.size(), is(0));
PropertySource<?> ps2 = new MapPropertySource("ps2", map2);
propertySources.add(ps1);
propertySources.add(ps2);
assertThat(propertySources.indexOf(PropertySource.named("ps1")), is(0));
assertThat(propertySources.indexOf(PropertySource.named("ps2")), is(1));
propertySources.clear();
}
代码示例来源:origin: org.springframework.boot/spring-boot
/**
* Attach a {@link ConfigurationPropertySource} support to the specified
* {@link Environment}. Adapts each {@link PropertySource} managed by the environment
* to a {@link ConfigurationPropertySource} and allows classic
* {@link PropertySourcesPropertyResolver} calls to resolve using
* {@link ConfigurationPropertyName configuration property names}.
* <p>
* The attached resolver will dynamically track any additions or removals from the
* underlying {@link Environment} property sources.
* @param environment the source environment (must be an instance of
* {@link ConfigurableEnvironment})
* @see #get(Environment)
*/
public static void attach(Environment environment) {
Assert.isInstanceOf(ConfigurableEnvironment.class, environment);
MutablePropertySources sources = ((ConfigurableEnvironment) environment)
.getPropertySources();
PropertySource<?> attached = sources.get(ATTACHED_PROPERTY_SOURCE_NAME);
if (attached != null && attached.getSource() != sources) {
sources.remove(ATTACHED_PROPERTY_SOURCE_NAME);
attached = null;
}
if (attached == null) {
sources.addFirst(new ConfigurationPropertySourcesPropertySource(
ATTACHED_PROPERTY_SOURCE_NAME,
new SpringConfigurationPropertySources(sources)));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
ConfigurableEnvironment environment = new MockEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
assertEquals(0, propertySources.size());
addInlinedPropertiesToEnvironment(environment, asArray(" "));
assertEquals(1, propertySources.size());
assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-context
@SuppressWarnings("unchecked")
private static Map<String, Object> findMap(PropertySource<?> propertySource) {
if (propertySource instanceof MapPropertySource) {
return (Map<String, Object>) propertySource.getSource();
}
return new LinkedHashMap<String, Object>();
}
代码示例来源:origin: ulisesbocchio/jasypt-spring-boot
public CachingDelegateEncryptablePropertySource(PropertySource<T> delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) {
super(delegate.getName(), delegate.getSource());
Assert.notNull(delegate, "PropertySource delegate cannot be null");
Assert.notNull(resolver, "EncryptablePropertyResolver cannot be null");
Assert.notNull(filter, "EncryptablePropertyFilter cannot be null");
this.delegate = delegate;
this.resolver = resolver;
this.filter = filter;
this.cache = new ConcurrentMapCache("encryptablePropertiesCache");
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-context
public EnvironmentManager(ConfigurableEnvironment environment) {
this.environment = environment;
MutablePropertySources sources = environment.getPropertySources();
if (sources.contains(MANAGER_PROPERTY_SOURCE)) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) sources
.get(MANAGER_PROPERTY_SOURCE).getSource();
this.map = map;
}
}
代码示例来源:origin: ulisesbocchio/jasypt-spring-boot
public EncryptablePropertySourceWrapper(PropertySource<T> delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) {
super(delegate.getName(), delegate.getSource());
encryptableDelegate = new CachingDelegateEncryptablePropertySource<>(delegate, resolver, filter);
}
代码示例来源:origin: spring-cloud/spring-cloud-commons
@SuppressWarnings("unchecked")
private static Map<String, Object> findMap(PropertySource<?> propertySource) {
if (propertySource instanceof MapPropertySource) {
return (Map<String, Object>) propertySource.getSource();
}
return new LinkedHashMap<String, Object>();
}
代码示例来源:origin: dangdangdotcom/config-toolkit
@Override
@PreDestroy
public void close() throws IOException {
super.getSource().close();
}
代码示例来源:origin: org.jmockring/jmockring-core
@Override
public ServerConfiguration getServerConfiguration() {
Map configMap = (Map) getEnvironment().getPropertySources().get(ConfigurationConstants.EXECUTION_ENVIRONMENT_KEY).getSource();
return (ServerConfiguration) configMap.get(ConfigurationConstants.SERVER_CONFIGURATION_KEY);
}
内容来源于网络,如有侵权,请联系作者删除!