List of usage examples for org.springframework.context.support PropertySourcesPlaceholderConfigurer PropertySourcesPlaceholderConfigurer
PropertySourcesPlaceholderConfigurer
From source file:uk.ac.kcl.batch.JobConfiguration.java
@Bean public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() { PropertySourcesPlaceholderConfigurer props = new PropertySourcesPlaceholderConfigurer(); props.setNullValue(""); return props; }
From source file:cn.org.once.cstack.initializer.CloudUnitApplicationContext.java
@Bean @Profile("integration") public static PropertySourcesPlaceholderConfigurer propertiesForIntegration() throws Exception { String file = "application-integration-local.properties"; String envIntegration = System.getenv("CLOUDUNIT_JENKINS_CI"); if ("true".equalsIgnoreCase(envIntegration)) { file = "application-integration.properties"; }/* w w w . java2s . c om*/ PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); pspc.setLocations(getResources(file)); pspc.setIgnoreUnresolvablePlaceholders(true); pspc.setLocalOverride(true); return pspc; }
From source file:org.springframework.cloud.aws.context.config.annotation.ContextCredentialsConfigurationRegistrarTest.java
@Test public void credentialsProvider_configWithAccessAndSecretKeyAsPlaceHolders_staticAwsCredentialsProviderConfiguredWithResolvedPlaceHolders() throws Exception { //Arrange// w w w. j av a 2s .c o m 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 assertNotNull(awsCredentialsProvider); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertEquals(1, credentialsProviders.size()); assertTrue(StaticCredentialsProvider.class.isInstance(credentialsProviders.get(0))); assertEquals("accessTest", awsCredentialsProvider.getCredentials().getAWSAccessKeyId()); assertEquals("testSecret", awsCredentialsProvider.getCredentials().getAWSSecretKey()); }
From source file:cn.org.once.cstack.initializer.CloudUnitApplicationContext.java
@Bean @Profile("test")/*from w w w . j a v a2 s .com*/ public static PropertySourcesPlaceholderConfigurer propertiesForTest() throws Exception { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new Resource[] { new ClassPathResource("application-test.properties") }; pspc.setLocations(resources); pspc.setIgnoreUnresolvablePlaceholders(true); pspc.setLocalOverride(true); return pspc; }
From source file:com.indeed.imhotep.web.config.SpringConfiguration.java
public static @Bean PropertySourcesPlaceholderConfigurer placeholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); }
From source file:de.thm.arsnova.config.SecurityConfig.java
@Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setLocations(new Resource[] { new ClassPathResource("arsnova.properties.example"), new FileSystemResource("file:///etc/arsnova/arsnova.properties"), }); configurer.setIgnoreResourceNotFound(true); configurer.setIgnoreUnresolvablePlaceholders(false); return configurer; }
From source file:org.springframework.cloud.aws.context.config.xml.ContextCredentialsBeanDefinitionParserTest.java
@Test public void parseBean_withProfileCredentialsProviderAndProfileFile_createProfileCredentialsProvider() throws IOException { GenericApplicationContext applicationContext = new GenericApplicationContext(); Map<String, Object> secretAndAccessKeyMap = new HashMap<>(); secretAndAccessKeyMap.put("profilePath", new ClassPathResource(getClass().getSimpleName() + "-profile", getClass()).getFile() .getAbsolutePath()); applicationContext.getEnvironment().getPropertySources() .addLast(new MapPropertySource("test", secretAndAccessKeyMap)); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setPropertySources(applicationContext.getEnvironment().getPropertySources()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext); reader.loadBeanDefinitions(new ClassPathResource( getClass().getSimpleName() + "-profileCredentialsProviderWithFile.xml", getClass())); applicationContext.refresh();/* w ww . j av a 2s .c o m*/ AWSCredentialsProvider provider = applicationContext.getBean( AmazonWebserviceClientConfigurationUtils.CREDENTIALS_PROVIDER_BEAN_NAME, AWSCredentialsProvider.class); assertNotNull(provider); assertEquals("testAccessKey", provider.getCredentials().getAWSAccessKeyId()); assertEquals("testSecretKey", provider.getCredentials().getAWSSecretKey()); }
From source file:com.kixeye.chassis.bootstrap.Application.java
private void createChildContext() { if (appMetadata.isWebapp()) { applicationContext = new AnnotationConfigWebApplicationContext(); if (appMetadata.getConfigurationClasses().length > 0) { ((AnnotationConfigWebApplicationContext) applicationContext) .register(appMetadata.getConfigurationClasses()); }//w w w . j a va2 s. c o m } else { applicationContext = new AnnotationConfigApplicationContext(); if (appMetadata.getConfigurationClasses().length > 0) { ((AnnotationConfigApplicationContext) applicationContext) .register(appMetadata.getConfigurationClasses()); } } applicationContext.setParent(bootstrapApplicationContext); applicationContext.getEnvironment().getPropertySources() .addFirst(new ArchaiusSpringPropertySource(appMetadata.getName() + "-archaius")); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setEnvironment(applicationContext.getEnvironment()); applicationContext.addBeanFactoryPostProcessor(configurer); applicationContext.setId(appMetadata.getName()); applicationContext.refresh(); }
From source file:org.springframework.cloud.aws.context.config.annotation.ContextCredentialsConfigurationRegistrarTest.java
@Test public void credentialsProvider_configWithProfileNameAndCustomProfilePath_profileCredentialsProviderConfigured() throws Exception { //Arrange/* w w w. ja v a2 s . c o m*/ 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 assertNotNull(awsCredentialsProvider); @SuppressWarnings("unchecked") List<CredentialsProvider> credentialsProviders = (List<CredentialsProvider>) ReflectionTestUtils .getField(awsCredentialsProvider, "credentialsProviders"); assertEquals(1, credentialsProviders.size()); assertTrue(ProfileCredentialsProvider.class.isInstance(credentialsProviders.get(0))); ProfileCredentialsProvider provider = (ProfileCredentialsProvider) credentialsProviders.get(0); assertEquals("testAccessKey", provider.getCredentials().getAWSAccessKeyId()); assertEquals("testSecretKey", provider.getCredentials().getAWSSecretKey()); }
From source file:org.finra.dm.dao.config.DaoSpringModuleConfig.java
/** * The database supplied property sources placeholder configurer that allows access to externalized properties from a database. This method also adds a new * property source that contains the database properties to the environment. * * @return the property sources placeholder configurer. *//*from w w w . j a va 2 s . c o m*/ @Bean public static PropertySourcesPlaceholderConfigurer databasePropertySourcesPlaceholderConfigurer() { // Get the configurable environment and add a new property source to it that contains the database properties. // That way, the properties can be accessed via the environment or via an injected @Value annotation. // We are adding this property source last so other property sources (e.g. system properties, environment variables) can be used // to override the database properties. Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment(); if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment; ReloadablePropertySource reloadablePropertySource = new ReloadablePropertySource( ReloadablePropertySource.class.getName(), ConfigurationConverter.getProperties(getPropertyDatabaseConfiguration()), getPropertyDatabaseConfiguration()); configurableEnvironment.getPropertySources().addLast(reloadablePropertySource); } return new PropertySourcesPlaceholderConfigurer(); }