当前位置: 首页>>代码示例>>Java>>正文


Java CompositePropertySource类代码示例

本文整理汇总了Java中org.springframework.core.env.CompositePropertySource的典型用法代码示例。如果您正苦于以下问题:Java CompositePropertySource类的具体用法?Java CompositePropertySource怎么用?Java CompositePropertySource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompositePropertySource类属于org.springframework.core.env包,在下文中一共展示了CompositePropertySource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializePropertySources

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
protected void initializePropertySources() {
  if (environment.getPropertySources().contains(APOLLO_PROPERTY_SOURCE_NAME)) {
    //already initialized
    return;
  }
  CompositePropertySource composite = new CompositePropertySource(APOLLO_PROPERTY_SOURCE_NAME);

  //sort by order asc
  ImmutableSortedSet<Integer> orders = ImmutableSortedSet.copyOf(NAMESPACE_NAMES.keySet());
  Iterator<Integer> iterator = orders.iterator();

  while (iterator.hasNext()) {
    int order = iterator.next();
    for (String namespace : NAMESPACE_NAMES.get(order)) {
      Config config = ConfigService.getConfig(namespace);

      composite.addPropertySource(new ConfigPropertySource(namespace, config));
    }
  }
  environment.getPropertySources().addFirst(composite);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:22,代码来源:PropertySourcesProcessor.java

示例2: configurePropertySources

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
/**
 * Add, remove or re-order any {@link PropertySource}s in this application's
 * environment.
 * @param environment this application's environment
 * @param args arguments passed to the {@code run} method
 * @see #configureEnvironment(ConfigurableEnvironment, String[])
 */
protected void configurePropertySources(ConfigurableEnvironment environment,
		String[] args) {
	MutablePropertySources sources = environment.getPropertySources();
	if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
		sources.addLast(
				new MapPropertySource("defaultProperties", this.defaultProperties));
	}
	if (this.addCommandLineProperties && args.length > 0) {
		String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
		if (sources.contains(name)) {
			PropertySource<?> source = sources.get(name);
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(new SimpleCommandLinePropertySource(
					name + "-" + args.hashCode(), args));
			composite.addPropertySource(source);
			sources.replace(name, composite);
		}
		else {
			sources.addFirst(new SimpleCommandLinePropertySource(args));
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:30,代码来源:SpringApplication.java

示例3: findPropertySources

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
/**
 * Finds all registered property sources of the given type.
 */
protected <S extends PropertySource<?>> List<S> findPropertySources(Class<S> sourceClass) {
    List<S> managedSources = new LinkedList<>();

    LinkedList<PropertySource<?>> sources = toLinkedList(environment.getPropertySources());
    while (!sources.isEmpty()) {
        PropertySource<?> source = sources.pop();
        if (source instanceof CompositePropertySource) {
            CompositePropertySource comp = (CompositePropertySource) source;
            sources.addAll(comp.getPropertySources());
        } else if (sourceClass.isInstance(source)) {
            managedSources.add(sourceClass.cast(source));
        }
    }

    return managedSources;
}
 
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:20,代码来源:ConfigurationChangeDetector.java

示例4: shouldLocateLeaseAwareSources

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Test
public void shouldLocateLeaseAwareSources() {

	RequestedSecret rotating = RequestedSecret.rotating("secret/rotating");
	DefaultSecretBackendConfigurer configurer = new DefaultSecretBackendConfigurer();
	configurer.add(rotating);
	configurer.add("database/mysql/creds/readonly");

	propertySourceLocator = new LeasingVaultPropertySourceLocator(
			new VaultProperties(), configurer, secretLeaseContainer);

	PropertySource<?> propertySource = propertySourceLocator
			.locate(configurableEnvironment);

	assertThat(propertySource).isInstanceOf(CompositePropertySource.class);

	verify(secretLeaseContainer).addRequestedSecret(rotating);
	verify(secretLeaseContainer).addRequestedSecret(
			RequestedSecret.renewable("database/mysql/creds/readonly"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:21,代码来源:LeasingVaultPropertySourceLocatorUnitTests.java

示例5: shouldLocatePropertySourcesInVaultApplicationContext

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Test
public void shouldLocatePropertySourcesInVaultApplicationContext() {

	VaultGenericBackendProperties backendProperties = new VaultGenericBackendProperties();
	backendProperties.setApplicationName("wintermute");

	propertySourceLocator = new VaultPropertySourceLocator(operations,
			new VaultProperties(),
			VaultPropertySourceLocatorSupport.createConfiguration(backendProperties));

	when(configurableEnvironment.getActiveProfiles())
			.thenReturn(new String[] { "vermillion", "periwinkle" });

	PropertySource<?> propertySource = propertySourceLocator
			.locate(configurableEnvironment);

	assertThat(propertySource).isInstanceOf(CompositePropertySource.class);

	CompositePropertySource composite = (CompositePropertySource) propertySource;
	assertThat(composite.getPropertySources()).extracting("name").containsSequence(
			"secret/wintermute/periwinkle", "secret/wintermute/vermillion",
			"secret/wintermute");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:24,代码来源:VaultPropertySourceLocatorUnitTests.java

示例6: shouldLocatePropertySourcesInEachPathSpecifiedWhenApplicationNameContainsSeveral

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Test
public void shouldLocatePropertySourcesInEachPathSpecifiedWhenApplicationNameContainsSeveral() {

	VaultGenericBackendProperties backendProperties = new VaultGenericBackendProperties();
	backendProperties.setApplicationName("wintermute,straylight,icebreaker/armitage");

	propertySourceLocator = new VaultPropertySourceLocator(operations,
			new VaultProperties(),
			VaultPropertySourceLocatorSupport.createConfiguration(backendProperties));

	when(configurableEnvironment.getActiveProfiles())
			.thenReturn(new String[] { "vermillion", "periwinkle" });

	PropertySource<?> propertySource = propertySourceLocator
			.locate(configurableEnvironment);

	assertThat(propertySource).isInstanceOf(CompositePropertySource.class);

	CompositePropertySource composite = (CompositePropertySource) propertySource;
	assertThat(composite.getPropertySources()).extracting("name").contains(
			"secret/wintermute", "secret/straylight", "secret/icebreaker/armitage",
			"secret/wintermute/vermillion", "secret/wintermute/periwinkle",
			"secret/straylight/vermillion", "secret/straylight/periwinkle",
			"secret/icebreaker/armitage/vermillion",
			"secret/icebreaker/armitage/periwinkle");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:27,代码来源:VaultPropertySourceLocatorUnitTests.java

示例7: shouldCreatePropertySourcesInOrder

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Test
public void shouldCreatePropertySourcesInOrder() {

	DefaultSecretBackendConfigurer configurer = new DefaultSecretBackendConfigurer();
	configurer.add(new MySecondSecretBackendMetadata());
	configurer.add(new MyFirstSecretBackendMetadata());

	propertySourceLocator = new VaultPropertySourceLocator(operations,
			new VaultProperties(), configurer);

	PropertySource<?> propertySource = propertySourceLocator
			.locate(configurableEnvironment);

	assertThat(propertySource).isInstanceOf(CompositePropertySource.class);

	CompositePropertySource composite = (CompositePropertySource) propertySource;
	assertThat(composite.getPropertySources()).extracting("name")
			.containsSequence("foo", "bar");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:20,代码来源:VaultPropertySourceLocatorUnitTests.java

示例8: createPropertySource

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
private PropertySource createPropertySource(AnnotationAttributes attributes, ConfigurableEnvironment environment, ResourceLoader resourceLoader, EncryptablePropertyResolver resolver, List<PropertySourceLoader> loaders) throws Exception {
    String name = generateName(attributes.getString("name"));
    String[] locations = attributes.getStringArray("value");
    boolean ignoreResourceNotFound = attributes.getBoolean("ignoreResourceNotFound");
    CompositePropertySource compositePropertySource = new CompositePropertySource(name);
    Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required");
    for (String location : locations) {
        String resolvedLocation = environment.resolveRequiredPlaceholders(location);
        Resource resource = resourceLoader.getResource(resolvedLocation);
        if (!resource.exists()) {
            if (!ignoreResourceNotFound) {
                throw new IllegalStateException(String.format("Encryptable Property Source '%s' from location: %s Not Found", name, resolvedLocation));
            } else {
                log.info("Ignoring NOT FOUND Encryptable Property Source '{}' from locations: {}", name, resolvedLocation);
            }
        } else {
            String actualName = name + "#" + resolvedLocation;
            loadPropertySource(loaders, resource, actualName)
                    .ifPresent(compositePropertySource::addPropertySource);
        }
    }
    return new EncryptableEnumerablePropertySourceWrapper<>(compositePropertySource, resolver);
}
 
开发者ID:ulisesbocchio,项目名称:jasypt-spring-boot,代码行数:24,代码来源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例9: serviceUrlWithCompositePropertySource

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@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",
					"http://example.com,http://example2.com")));
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			TestConfiguration.class);
	this.context.refresh();
	assertEquals("{defaultZone=http://example.com,http://example2.com}",
			this.context.getBean(EurekaClientConfigBean.class).getServiceUrl()
					.toString());
	assertEquals("[http://example.com/, http://example2.com/]",
			getEurekaServiceUrlsForDefaultZone());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:17,代码来源:EurekaClientConfigBeanTests.java

示例10: doHealthCheck

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Override
  protected void doHealthCheck(Builder builder) throws Exception {
PropertySource<?> propertySource = getPropertySource();
builder.up();
if (propertySource instanceof CompositePropertySource) {
	List<String> sources = new ArrayList<>();
	for (PropertySource<?> ps : ((CompositePropertySource) propertySource).getPropertySources()) {
		sources.add(ps.getName());
	}
	builder.withDetail("propertySources", sources);
} else if (propertySource!=null) {
	builder.withDetail("propertySources", propertySource.toString());
} else {
	builder.unknown().withDetail("error", "no property sources located");
}
  }
 
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:17,代码来源:ConfigServerHealthIndicator.java

示例11: propertySourcesFound

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Test
public void propertySourcesFound() throws Exception {
	String foo = this.environment.getProperty("foo");
	assertThat("foo was wrong", foo, is(equalTo("bar-app-dev")));

	String myBaz = this.environment.getProperty("my.baz");
	assertThat("my.baz was wrong", myBaz, is(equalTo("bar-app-dev")));

	MutablePropertySources propertySources = this.environment.getPropertySources();
	PropertySource<?> bootstrapProperties = propertySources.get("bootstrapProperties");
	assertThat("bootstrapProperties was null", bootstrapProperties, is(notNullValue()));
	assertThat("bootstrapProperties was wrong type", bootstrapProperties.getClass(), is(typeCompatibleWith(CompositePropertySource.class)));

	Collection<PropertySource<?>> consulSources = ((CompositePropertySource) bootstrapProperties).getPropertySources();
	assertThat("consulSources was wrong size", consulSources, hasSize(1));

	PropertySource<?> consulSource = consulSources.iterator().next();
	assertThat("consulSource was wrong type", consulSource.getClass(), is(typeCompatibleWith(CompositePropertySource.class)));
	Collection<PropertySource<?>> fileSources = ((CompositePropertySource) consulSource).getPropertySources();
	assertThat("fileSources was wrong size", fileSources, hasSize(4));

	assertFileSourceNames(fileSources, APP_NAME_DEV_PROPS, APP_NAME_PROPS, APPLICATION_DEV_YML, APPLICATION_YML);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:24,代码来源:ConsulPropertySourceLocatorFilesTests.java

示例12: locate

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@Override
public PropertySource<?> locate(final Environment environment) {
    if (environment instanceof ConfigurableEnvironment) {
        final String sourceName = MongoDbPropertySource.class.getSimpleName();
        final CompositePropertySource composite = new CompositePropertySource(sourceName);
        final MongoDbPropertySource source = new MongoDbPropertySource(sourceName, mongo);
        composite.addFirstPropertySource(source);
        return composite;
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:12,代码来源:MongoDbPropertySourceLocator.java

示例13: collatePropertySources

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
private PropertySource<?> collatePropertySources(String name, List<ResourcePropertySource> propertySources) {
	if (propertySources.size() == 1) {
		return propertySources.get(0).withName(name);
	}
	CompositePropertySource result = new CompositePropertySource(name);
	for (int i = propertySources.size() - 1; i >= 0; i--) {
		result.addPropertySource(propertySources.get(i));
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ConfigurationClassParser.java

示例14: processPropertySource

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static void processPropertySource(PropertySource propertySource, String prefix, Map<String, Object> result,
		boolean removePrefix) {
	if (propertySource instanceof MapPropertySource) {
		MapPropertySource mapPropertySource = (MapPropertySource) propertySource;
		processMap(mapPropertySource, prefix, result, removePrefix);
	} else if (propertySource instanceof CompositePropertySource) {
		CompositePropertySource compositePropertySource = (CompositePropertySource) propertySource;
		for (PropertySource sub : compositePropertySource.getPropertySources()) {
			processPropertySource(sub, prefix, result, removePrefix);
		}
	}
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:14,代码来源:EnvPropertyMapper.java

示例15: addPropertySource

import org.springframework.core.env.CompositePropertySource; //导入依赖的package包/类
private void addPropertySource(ResourcePropertySource propertySource) {
	String name = propertySource.getName();
	MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
	if (propertySources.contains(name) && this.propertySourceNames.contains(name)) {
		// We've already added a version, we need to extend it
		PropertySource<?> existing = propertySources.get(name);
		if (existing instanceof CompositePropertySource) {
			((CompositePropertySource) existing).addFirstPropertySource(propertySource.withResourceName());
		}
		else {
			if (existing instanceof ResourcePropertySource) {
				existing = ((ResourcePropertySource) existing).withResourceName();
			}
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(propertySource.withResourceName());
			composite.addPropertySource(existing);
			propertySources.replace(name, composite);
		}
	}
	else {
		if (this.propertySourceNames.isEmpty()) {
			propertySources.addLast(propertySource);
		}
		else {
			String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
			propertySources.addBefore(firstProcessed, propertySource);
		}
	}
	this.propertySourceNames.add(name);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:ConfigurationClassParser.java


注:本文中的org.springframework.core.env.CompositePropertySource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。