Example usage for org.springframework.context.support FileSystemXmlApplicationContext addBeanFactoryPostProcessor

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext addBeanFactoryPostProcessor

Introduction

In this page you can find the example usage for org.springframework.context.support FileSystemXmlApplicationContext addBeanFactoryPostProcessor.

Prototype

@Override
    public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) 

Source Link

Usage

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();//from ww  w. ja va 2  s  . c  o m

    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");
}