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

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

Introduction

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

Prototype

public void setLocalOverride(boolean localOverride) 

Source Link

Document

Set whether local properties override properties from files.

Usage

From source file:info.naiv.lab.java.tool.sqlite.exporter.AppSettings.java

/**
 *
 * @return/*from www .  j av  a 2s.co  m*/
 */
@Bean(name = "externalProperties")
public PropertiesFactoryBean propertiesFactoryBean() {

    Properties p = new Properties();
    setPropertyIfNotBlank(p, "datasource.url", sourceUrl);
    setPropertyIfNotBlank(p, "datasource.schema", sourceSchema);
    setPropertyIfNotBlank(p, "datasource.username", sourceUsername);
    setPropertyIfNotBlank(p, "datasource.password", sourcePassword);
    setPropertyIfNotBlank(p, "jdbc.driver.directory", jdbcDriverDirectory);

    PropertiesFactoryBean bean = new ResolvablePropertiesFactoryBean();
    bean.setIgnoreResourceNotFound(true);
    bean.setLocation(new FileSystemResource(propertyLocation));
    bean.setProperties(p);
    bean.setLocalOverride(true);
    return bean;
}

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

@Bean(name = { BEAN_LOGSNIFFER_PROPS })
@Autowired//from   w ww. j av a 2s.c  o  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;
}