Java Code Examples for org.springframework.context.support.PropertySourcesPlaceholderConfigurer#setPropertySources()

The following examples show how to use org.springframework.context.support.PropertySourcesPlaceholderConfigurer#setPropertySources() . 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: OverrideProperties.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreResourceNotFound(true);
    configurer.setIgnoreUnresolvablePlaceholders(true);
    MutablePropertySources propertySources = new MutablePropertySources();
    MockPropertySource source = new MockPropertySource()
        .withProperty("rabbitmq.host", "192.168.10.10")
        .withProperty("rabbitmq.port", "5673")
        .withProperty("rabbitmq.username", "jfw")
        .withProperty("rabbitmq.password", "jfw")
        .withProperty("rabbitmq.channel-cache-size", 100);
    propertySources.addLast(source);
    configurer.setPropertySources(propertySources);
    return configurer;
}
 
Example 2
Source File: InvalidProperties.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreResourceNotFound(true);
    configurer.setIgnoreUnresolvablePlaceholders(true);
    MutablePropertySources propertySources = new MutablePropertySources();
    MockPropertySource source = new MockPropertySource()
        .withProperty("rabbitmq.port", "invalid");
    propertySources.addLast(source);
    configurer.setPropertySources(propertySources);
    return configurer;
}
 
Example 3
Source File: DefaultProperties.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreResourceNotFound(true);
    configurer.setIgnoreUnresolvablePlaceholders(true);
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MockPropertySource());
    configurer.setPropertySources(propertySources);
    return configurer;
}
 
Example 4
Source File: ContextCredentialsConfigurationRegistrarTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void credentialsProvider_configWithAccessAndSecretKeyAsPlaceHolders_staticAwsCredentialsProviderConfiguredWithResolvedPlaceHolders()
		throws Exception {
	// @checkstyle:on
	// Arrange
	this.context = new AnnotationConfigApplicationContext();

	Map<String, Object> secretAndAccessKeyMap = new HashMap<>();
	secretAndAccessKeyMap.put("accessKey", "accessTest");
	secretAndAccessKeyMap.put("secretKey", "testSecret");

	this.context.getEnvironment().getPropertySources()
			.addLast(new MapPropertySource("test", secretAndAccessKeyMap));
	PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
	configurer.setPropertySources(this.context.getEnvironment().getPropertySources());

	this.context.getBeanFactory().registerSingleton("configurer", configurer);
	this.context.register(
			ApplicationConfigurationWithAccessKeyAndSecretKeyAsPlaceHolder.class);
	this.context.refresh();
	// Act
	AWSCredentialsProvider awsCredentialsProvider = this.context
			.getBean(AWSCredentialsProvider.class);

	// Assert
	assertThat(awsCredentialsProvider).isNotNull();

	@SuppressWarnings("unchecked")
	List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils
			.getField(awsCredentialsProvider, "credentialsProviders");
	assertThat(credentialsProviders.size()).isEqualTo(1);
	assertThat(AWSStaticCredentialsProvider.class
			.isInstance(credentialsProviders.get(0))).isTrue();

	assertThat(awsCredentialsProvider.getCredentials().getAWSAccessKeyId())
			.isEqualTo("accessTest");
	assertThat(awsCredentialsProvider.getCredentials().getAWSSecretKey())
			.isEqualTo("testSecret");
}
 
Example 5
Source File: TestConfigurationPropertySource.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(
        final ConfigurableEnvironment env)
{
    final PropertySourcesPlaceholderConfigurer configurer =
            new PropertySourcesPlaceholderConfigurer();
    // https://jira.spring.io/browse/SPR-9631 may simplify this in
    // future
    final MutablePropertySources sources = new MutablePropertySources();
    sources.addLast(createConfigPropertySource());
    configurer.setPropertySources(sources);
    configurer.setEnvironment(env);
    return configurer;
}
 
Example 6
Source File: ContextCredentialsConfigurationRegistrarTest.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@Test
void credentialsProvider_configWithProfileNameAndCustomProfilePath_profileCredentialsProviderConfigured()
		throws Exception {
	// Arrange
	this.context = new AnnotationConfigApplicationContext();

	Map<String, Object> secretAndAccessKeyMap = new HashMap<>();
	secretAndAccessKeyMap.put("profilePath",
			new ClassPathResource(getClass().getSimpleName() + "-profile", getClass())
					.getFile().getAbsolutePath());

	this.context.getEnvironment().getPropertySources()
			.addLast(new MapPropertySource("test", secretAndAccessKeyMap));
	PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
	configurer.setPropertySources(this.context.getEnvironment().getPropertySources());

	this.context.getBeanFactory().registerSingleton("configurer", configurer);
	this.context
			.register(ApplicationConfigurationWithProfileAndCustomProfilePath.class);
	this.context.refresh();

	// Act
	AWSCredentialsProvider awsCredentialsProvider = this.context
			.getBean(AWSCredentialsProvider.class);

	// Assert
	assertThat(awsCredentialsProvider).isNotNull();

	@SuppressWarnings("unchecked")
	List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils
			.getField(awsCredentialsProvider, "credentialsProviders");
	assertThat(credentialsProviders.size()).isEqualTo(1);
	assertThat(
			ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(0)))
					.isTrue();

	ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders
			.get(0);
	assertThat(provider.getCredentials().getAWSAccessKeyId())
			.isEqualTo("testAccessKey");
	assertThat(provider.getCredentials().getAWSSecretKey())
			.isEqualTo("testSecretKey");
}