Example usage for org.springframework.beans.factory.config PropertiesFactoryBean PropertiesFactoryBean

List of usage examples for org.springframework.beans.factory.config PropertiesFactoryBean PropertiesFactoryBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config PropertiesFactoryBean PropertiesFactoryBean.

Prototype

PropertiesFactoryBean

Source Link

Usage

From source file:com.zekke.webapp.config.TestConfig.java

@Bean
public static PropertiesFactoryBean configProperties(ResourceLoader resourceLoader) throws IOException {
    PropertiesFactoryBean props = new PropertiesFactoryBean();
    props.setLocation(resourceLoader.getResource(CONFIG_PROPERTIES_URI));
    props.afterPropertiesSet();/*from ww w. j  ava  2s  .c o  m*/
    return props;
}

From source file:com.zekke.webapp.config.MainConfig.java

/**
 * Creates a new Properties./*from w  w w  .  ja  v a  2 s. c  o m*/
 *
 * @param resourceLoader any ResourceLoader.
 * @return a Properties.
 * @throws IOException if the properties file is not found in
 * {@link #CONFIG_PROPERTIES_URI}.
 */
@Bean
public static PropertiesFactoryBean configProperties(ResourceLoader resourceLoader) throws IOException {
    PropertiesFactoryBean props = new PropertiesFactoryBean();
    props.setLocation(resourceLoader.getResource(CONFIG_PROPERTIES_URI));
    props.afterPropertiesSet();
    return props;
}

From source file:org.uoiu.platform.web.MvcConfig.java

@Bean
public PropertiesFactoryBean applicationProps() {
    PropertiesFactoryBean applicationProps = new PropertiesFactoryBean();
    //    applicationProps.setLocation(new ClassPathResource(
    //      "/WEB-INF/spring/application.properties"));
    return applicationProps;
}

From source file:com.orange.clara.pivotaltrackermirror.config.QuartzConfig.java

@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}

From source file:net.cloudkit.enterprises.infrastructure.configuration.ApplicationConfiguration.java

public PropertiesFactoryBean propertiesFactoryBean() {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    Properties properties = new Properties();
    properties.put("text", 123456);
    propertiesFactoryBean.setProperties(properties);

    propertiesFactoryBean.setLocations();
    propertiesFactoryBean.setFileEncoding("UTF-8");
    return propertiesFactoryBean;
}

From source file:com.logsniffer.app.CoreAppConfig.java

@Bean(name = { BEAN_LOGSNIFFER_PROPS })
@Autowired//from  w ww.ja  va 2 s  . co  m
public PropertiesFactoryBean logSnifferProperties(final ApplicationContext ctx) throws IOException {
    if (ctx.getEnvironment().acceptsProfiles("!" + ContextProvider.PROFILE_NONE_QA)) {
        final File qaFile = File.createTempFile("logsniffer", "qa");
        qaFile.delete();
        final String qaHomeDir = qaFile.getPath();
        logger.info("QA mode active, setting random home directory: {}", qaHomeDir);
        System.setProperty("logsniffer.home", qaHomeDir);
    }
    final PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver();
    Resource[] classPathProperties = pathMatcher.getResources("classpath*:/config/**/logsniffer-*.properties");
    final Resource[] metainfProperties = pathMatcher
            .getResources("classpath*:/META-INF/**/logsniffer-*.properties");
    final PropertiesFactoryBean p = new PropertiesFactoryBean();
    for (final Resource r : metainfProperties) {
        classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, r);
    }
    classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties,
            new FileSystemResource(System.getProperty("logsniffer.home") + "/" + LOGSNIFFER_PROPERTIES_FILE));
    p.setLocations(classPathProperties);
    p.setProperties(System.getProperties());
    p.setLocalOverride(true);
    p.setIgnoreResourceNotFound(true);
    return p;
}

From source file:edu.harvard.i2b2.fr.util.FRUtil.java

/**
 * Load application property file into memory
 *//*from  ww w . j  a v a  2  s.  c o m*/
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        //read application directory property file
        loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        //read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }
        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;
        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:dubbo.spring.javaconfig.DatabaseConfig.java

/**
 * ??/*from ww w  .  j  av  a2s. c o  m*/
 * @return
 */
@Bean
public PropertiesFactoryBean dbConfig() {
    PropertiesFactoryBean dbConfig = new PropertiesFactoryBean();
    dbConfig.setLocation(new ClassPathResource("database.properties"));
    return dbConfig;
}

From source file:dubbo.spring.javaconfig.DatabaseConfig.java

/**
 * hibernate ? envers ?/*from w  w w .  ja  va  2 s.c o m*/
 * @return
 */
@Bean
public PropertiesFactoryBean hibernateConfig() {
    PropertiesFactoryBean dbConfig = new PropertiesFactoryBean();
    dbConfig.setLocation(new ClassPathResource("hibernate.properties"));
    return dbConfig;
}

From source file:edu.harvard.i2b2.pm.util.PMUtil.java

/**
 * Load application property file into memory
 */// w  w w  .j  ava  2 s  . c om
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        //read application directory property file
        Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);

        //read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }

        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;

        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }

        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}