Search in sources :

Example 6 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project tutorials by eugenp.

the class ParentConfig2 method configurer.

@Bean
public static PropertyPlaceholderConfigurer configurer() {
    final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocations(new ClassPathResource("parent.properties"));
    return ppc;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Example 7 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project jim-framework by jiangmin168168.

the class WebApplicationConfig method properties.

@Bean
public static PropertyPlaceholderConfigurer properties() {
    SpringPropertyInjectSupport springPropertyInjectSupport = new SpringPropertyInjectSupport();
    springPropertyInjectSupport.setConfigNameSpaces("configcenter/" + System.getProperty("env"));
    springPropertyInjectSupport.init();
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Resource[] resources = new ClassPathResource[] { new ClassPathResource("application.properties") };
    ppc.setLocations(resources);
    ppc.setIgnoreUnresolvablePlaceholders(true);
    return ppc;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) SpringPropertyInjectSupport(com.jim.framework.configcenter.spring.SpringPropertyInjectSupport) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project eol-globi-data by jhpoelen.

the class Config method properties.

@Bean
public static PropertyPlaceholderConfigurer properties() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setIgnoreResourceNotFound(true);
    ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    return ppc;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 9 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project webapp by elimu-ai.

the class EnvironmentContextLoaderListener method customizeContext.

@Override
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
    logger.info("customizeContext");
    // Load default settings
    try {
        Resource resourceConfig = new ServletContextResourceLoader(servletContext).getResource("classpath:config.properties");
        PROPERTIES.load(resourceConfig.getInputStream());
        Resource resourceJdbc = new ServletContextResourceLoader(servletContext).getResource("classpath:jdbc.properties");
        PROPERTIES.load(resourceJdbc.getInputStream());
        logger.debug("properties (before overriding): " + PROPERTIES);
    } catch (IOException ex) {
        logger.error(ex);
    }
    if ((env == Environment.TEST) || (env == Environment.PROD)) {
        InputStream inputStream = null;
        try {
            // Override config.properties
            Resource resourceConfig = new ServletContextResourceLoader(servletContext).getResource("classpath:config_" + env + ".properties");
            PROPERTIES.load(resourceConfig.getInputStream());
            // Override jdbc.properties
            Resource resourceJdbc = new ServletContextResourceLoader(servletContext).getResource("classpath:jdbc_" + env + ".properties");
            PROPERTIES.load(resourceJdbc.getInputStream());
            String contentLanguage = (String) servletContext.getAttribute("content_language");
            logger.info("contentLanguage: " + contentLanguage);
            PROPERTIES.put("content.language", contentLanguage);
            String jdbcUrl = (String) servletContext.getAttribute("jdbc_url");
            PROPERTIES.put("jdbc.url", jdbcUrl);
            String jdbcUsername = (String) servletContext.getAttribute("jdbc_username");
            PROPERTIES.put("jdbc.username", jdbcUsername);
            String jdbcPasswordAttr = (String) servletContext.getAttribute("jdbc_password");
            PROPERTIES.put("jdbc.password", jdbcPasswordAttr);
            String googleApiSecret = (String) servletContext.getAttribute("google_api_secret");
            PROPERTIES.put("google.api.secret", googleApiSecret);
            String gitHubApiSecret = (String) servletContext.getAttribute("github_api_secret");
            PROPERTIES.put("github.api.secret", gitHubApiSecret);
            String covalentApiKey = (String) servletContext.getAttribute("covalent_api_key");
            PROPERTIES.put("covalent.api.key", covalentApiKey);
            if (env == Environment.PROD) {
                String discordWebhookUrl = (String) servletContext.getAttribute("discord_webhook_url");
                PROPERTIES.put("discord.webhook.url", discordWebhookUrl);
            }
            logger.debug("properties (after overriding): " + PROPERTIES);
        } catch (FileNotFoundException ex) {
            logger.error(ex);
        } catch (IOException ex) {
            logger.error(ex);
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException ex) {
                logger.error(ex);
            }
        }
        PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
        propertyPlaceholderConfigurer.setProperties(PROPERTIES);
        applicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

            @Override
            public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
                PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
                propertyPlaceholderConfigurer.setProperties(PROPERTIES);
                propertyPlaceholderConfigurer.postProcessBeanFactory(configurableListableBeanFactory);
            }
        });
    }
    // Add all supported languages
    PROPERTIES.put("supported.languages", Language.values());
    // Add config properties to application scope
    servletContext.setAttribute("configProperties", PROPERTIES);
    servletContext.setAttribute("newLineCharRn", "\r\n");
    servletContext.setAttribute("newLineCharR", "\r");
    servletContext.setAttribute("newLineCharR", "\n");
    super.customizeContext(servletContext, applicationContext);
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ServletContextResourceLoader(org.springframework.web.context.support.ServletContextResourceLoader) BeansException(org.springframework.beans.BeansException)

Example 10 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project kylo by Teradata.

the class TestConfig method propConfig.

@Bean
public PropertyPlaceholderConfigurer propConfig() {
    PropertyPlaceholderConfigurer placeholderConfigurer = new PropertyPlaceholderConfigurer();
    placeholderConfigurer.setLocation(new ClassPathResource("config.properties"));
    return placeholderConfigurer;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Aggregations

PropertyPlaceholderConfigurer (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)19 Bean (org.springframework.context.annotation.Bean)12 ClassPathResource (org.springframework.core.io.ClassPathResource)8 Properties (java.util.Properties)6 Resource (org.springframework.core.io.Resource)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 Test (org.junit.Test)2 DisconfMgrBean (com.baidu.disconf.client.DisconfMgrBean)1 ReloadablePropertiesFactoryBean (com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean)1 ReloadingPropertyPlaceholderConfigurer (com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer)1 SpringPropertyInjectSupport (com.jim.framework.configcenter.spring.SpringPropertyInjectSupport)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1