Search in sources :

Example 16 with PropertySourcesPlaceholderConfigurer

use of org.springframework.context.support.PropertySourcesPlaceholderConfigurer in project spring-boot by spring-projects.

the class ConfigurationPropertiesBindingPostProcessor method getSinglePropertySourcesPlaceholderConfigurer.

private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
    // Take care not to cause early instantiation of all FactoryBeans
    if (this.beanFactory instanceof ListableBeanFactory) {
        ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory;
        Map<String, PropertySourcesPlaceholderConfigurer> beans = listableBeanFactory.getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false, false);
        if (beans.size() == 1) {
            return beans.values().iterator().next();
        }
        if (beans.size() > 1 && logger.isWarnEnabled()) {
            logger.warn("Multiple PropertySourcesPlaceholderConfigurer " + "beans registered " + beans.keySet() + ", falling back to Environment");
        }
    }
    return null;
}
Also used : PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 17 with PropertySourcesPlaceholderConfigurer

use of org.springframework.context.support.PropertySourcesPlaceholderConfigurer in project waltz by khartec.

the class DIConfiguration method propertySourcesPlaceholderConfigurer.

/* Required for property interpolation to work correctly */
/**
 * @see <a href="http://stackoverflow.com/a/41760877/2311919">Explanation</a>
 */
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(ConfigurableEnvironment env) {
    PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    JndiPropertySource jndiPropertySource = new JndiPropertySource("java:comp");
    env.getPropertySources().addFirst(jndiPropertySource);
    return placeholderConfigurer;
}
Also used : JndiPropertySource(org.springframework.jndi.JndiPropertySource) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer)

Example 18 with PropertySourcesPlaceholderConfigurer

use of org.springframework.context.support.PropertySourcesPlaceholderConfigurer in project molgenis by molgenis.

the class PlatformITConfig method properties.

@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
    Resource[] resources = new Resource[] { new ClassPathResource("/conf/molgenis.properties") };
    pspc.setLocations(resources);
    pspc.setFileEncoding("UTF-8");
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setIgnoreResourceNotFound(true);
    pspc.setNullValue("@null");
    return pspc;
}
Also used : Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 19 with PropertySourcesPlaceholderConfigurer

use of org.springframework.context.support.PropertySourcesPlaceholderConfigurer in project molgenis by molgenis.

the class MolgenisWebAppConfig method properties.

@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
    Resource[] resources = new Resource[] { new FileSystemResource(System.getProperty(MOLGENIS_HOME) + "/molgenis-server.properties"), new ClassPathResource("/molgenis.properties") };
    pspc.setLocations(resources);
    pspc.setFileEncoding("UTF-8");
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setIgnoreResourceNotFound(true);
    pspc.setNullValue("@null");
    return pspc;
}
Also used : Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Example 20 with PropertySourcesPlaceholderConfigurer

use of org.springframework.context.support.PropertySourcesPlaceholderConfigurer in project herd by FINRAOS.

the class DaoSpringModuleConfig method databasePropertySourcesPlaceholderConfigurer.

/**
 * 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.
 */
@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();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ReloadablePropertySource(org.finra.herd.dao.ReloadablePropertySource) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Environment(org.springframework.core.env.Environment) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

PropertySourcesPlaceholderConfigurer (org.springframework.context.support.PropertySourcesPlaceholderConfigurer)29 Bean (org.springframework.context.annotation.Bean)18 ClassPathResource (org.springframework.core.io.ClassPathResource)7 Properties (java.util.Properties)5 YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 Resource (org.springframework.core.io.Resource)3 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 MutablePropertySources (org.springframework.core.env.MutablePropertySources)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 JndiPropertySource (org.springframework.jndi.JndiPropertySource)2 ArchaiusSpringPropertySource (com.kixeye.chassis.bootstrap.spring.ArchaiusSpringPropertySource)1 SpringEnvironmentProperties (com.thinkbiganalytics.spring.SpringEnvironmentProperties)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 lombok.val (lombok.val)1 CasServerProperties (org.apereo.cas.configuration.model.core.CasServerProperties)1 ReloadablePropertySource (org.finra.herd.dao.ReloadablePropertySource)1 Test (org.junit.jupiter.api.Test)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1