Example usage for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setIgnoreResourceNotFound

List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setIgnoreResourceNotFound

Introduction

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

Prototype

public void setIgnoreResourceNotFound(boolean ignoreResourceNotFound) 

Source Link

Document

Set if failure to find the property resource should be ignored.

Usage

From source file:org.trustedanalytics.platformcontext.unit.TestConfiguration.java

@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {

    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setIgnoreResourceNotFound(true);
    final Properties properties = new Properties();
    properties.setProperty("cf.resource", ApiControllerTest.CF_RESOURCE);
    properties.setProperty("cf.cli.version", "");
    properties.setProperty("cf.cli.url", "");
    properties.setProperty("platform.version", "0.1");
    properties.setProperty("platform.coreorg", "coreOrg");
    ppc.setProperties(properties);/*from   ww  w .j  a  v a2  s  . c  o m*/

    return ppc;
}

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

/**
 * Returns a general properties placeholder configurer based on
 * {@link #logSnifferProperties()}./*www.  j  av  a 2 s. c  om*/
 * 
 * @param props
 *            autowired logSnifferProperties bean
 * @return A general properties placeholder configurer.
 * @throws IOException
 */
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Autowired
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer(
        @Qualifier(BEAN_LOGSNIFFER_PROPS) final Properties props) throws IOException {
    final PropertyPlaceholderConfigurer c = new PropertyPlaceholderConfigurer();
    c.setIgnoreResourceNotFound(true);
    c.setIgnoreUnresolvablePlaceholders(true);
    c.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    c.setProperties(props);
    return c;
}

From source file:ch.tatool.app.util.ContextUtils.java

/**
 * Create a new BeanFactory using the main ApplicationContext as parent.
 * //from w  ww .  j  a  va2  s.c om
 * @param classpath the path to the bean definition file in the classpath 
 * @param properties set of properties that should be replaced in the definitions
 * @return a BeanFactory instance
 */
public static BeanFactory createBeanFactory(String classpath, Properties properties) {
    // create an empty bean factory 
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

    // load the context file - has to be done here, otherwise properties won't get resolved
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    Resource resource = new ClassPathResource(classpath);
    reader.loadBeanDefinitions(resource);

    // apply the properties to the context
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setProperties(properties);
    configurer.setIgnoreUnresolvablePlaceholders(false);
    configurer.setIgnoreResourceNotFound(false);
    configurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK);
    configurer.postProcessBeanFactory(beanFactory);

    return beanFactory;
}

From source file:dk.nsi.minlog.export.config.ApplicationRootConfig.java

@Bean
public static PropertyPlaceholderConfigurer configuration() {
    final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
    props.setLocations(new Resource[] { new ClassPathResource("default.properties"),
            new FileSystemResource(getProperty("jboss.server.config.url") + "minlog." + getProperty("user.name")
                    + ".properties"),
            new ClassPathResource("minlog." + getProperty("user.name") + ".properties"),
            new ClassPathResource("jdbc.default.properties"),
            new FileSystemResource(getProperty("jboss.server.config.url") + "jdbc." + getProperty("user.name")
                    + ".properties"),
            new ClassPathResource("jdbc." + getProperty("user.name") + ".properties"),
            new FileSystemResource(getProperty("user.home") + "/.minlog/passwords.properties") });
    props.setIgnoreResourceNotFound(true);
    props.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);

    return props;
}

From source file:com.thinkbiganalytics.metadata.sla.TestConfiguration.java

@Bean
public PropertyPlaceholderConfigurer jiraPropertiesConfigurer() {
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setLocations(new ClassPathResource("/conf/sla.email.properties"));
    configurer.setIgnoreUnresolvablePlaceholders(true);
    configurer.setIgnoreResourceNotFound(true);
    return configurer;
}

From source file:net.frontlinesms.FrontlineSMS.java

/** Initialise {@link #applicationContext}. */
public void initApplicationContext() throws DataAccessResourceFailureException {
    // Load the data mode from the app.properties file
    AppProperties appProperties = AppProperties.getInstance();

    LOG.info("Load Spring/Hibernate application context to initialise DAOs");

    // Create a base ApplicationContext defining the hibernate config file we need to import
    StaticApplicationContext baseApplicationContext = new StaticApplicationContext();
    baseApplicationContext.registerBeanDefinition("hibernateConfigLocations",
            createHibernateConfigLocationsBeanDefinition());

    // Get the spring config locations
    String databaseExternalConfigPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath();
    String[] configLocations = getSpringConfigLocations(databaseExternalConfigPath);
    baseApplicationContext.refresh();/*ww  w  .  jav  a 2  s.com*/

    FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(configLocations,
            false, baseApplicationContext);
    this.applicationContext = applicationContext;

    // Add post-processor to handle substituted database properties
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    String databasePropertiesPath = ResourceUtils.getConfigDirectoryPath()
            + ResourceUtils.PROPERTIES_DIRECTORY_NAME + File.separatorChar
            + appProperties.getDatabaseConfigPath() + ".properties";
    propertyPlaceholderConfigurer.setLocation(new FileSystemResource(new File(databasePropertiesPath)));
    propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
    applicationContext.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);
    applicationContext.refresh();

    LOG.info("Context loaded successfully.");

    this.pluginManager = new PluginManager(this, applicationContext);

    LOG.info("Getting DAOs from application context...");
    groupDao = (GroupDao) applicationContext.getBean("groupDao");
    groupMembershipDao = (GroupMembershipDao) applicationContext.getBean("groupMembershipDao");
    contactDao = (ContactDao) applicationContext.getBean("contactDao");
    keywordDao = (KeywordDao) applicationContext.getBean("keywordDao");
    keywordActionDao = (KeywordActionDao) applicationContext.getBean("keywordActionDao");
    messageDao = (MessageDao) applicationContext.getBean("messageDao");
    emailDao = (EmailDao) applicationContext.getBean("emailDao");
    emailAccountDao = (EmailAccountDao) applicationContext.getBean("emailAccountDao");
    smsInternetServiceSettingsDao = (SmsInternetServiceSettingsDao) applicationContext
            .getBean("smsInternetServiceSettingsDao");
    smsModemSettingsDao = (SmsModemSettingsDao) applicationContext.getBean("smsModemSettingsDao");
    eventBus = (EventBus) applicationContext.getBean("eventBus");
}