Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getDefaultListableBeanFactory

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getDefaultListableBeanFactory

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getDefaultListableBeanFactory.

Prototype

public final DefaultListableBeanFactory getDefaultListableBeanFactory() 

Source Link

Document

Return the underlying bean factory of this context, available for registering bean definitions.

Usage

From source file:de.thischwa.pmcms.conf.BasicConfigurator.java

private void init() {
    if (System.getProperty("data.dir") == null)
        throw new IllegalArgumentException("No data directory set!");
    dataDir = new File(System.getProperty("data.dir"));
    if (!dataDir.exists())
        throw new IllegalArgumentException(
                String.format("Data directory not found: %s", dataDir.getAbsolutePath()));

    // load and merge the properties 
    loadProperties();//from   w  ww .  j  av  a2s  . co m

    // build special props
    String baseUrl = String.format("http://%s:%s/", props.get("pmcms.jetty.host"),
            props.get("pmcms.jetty.port"));
    props.setProperty("baseurl", baseUrl);
    props.setProperty("data.dir", dataDir.getAbsolutePath());
    System.setProperty("content.types.user.table",
            new File(Constants.APPLICATION_DIR, "lib/content-types.properties").getAbsolutePath());

    // init log4j
    LogManager.resetConfiguration();
    PropertyConfigurator.configure(PropertiesTool.getProperties(props, "log4j"));
    Logger logger = Logger.getLogger(BasicConfigurator.class);
    logger.info("*** log4j initialized!");

    // init the spring framework
    try {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.scan("de.thischwa.pmcms");
        PropertySourcesPlaceholderConfigurer config = new PropertySourcesPlaceholderConfigurer();
        config.setProperties(props);
        config.postProcessBeanFactory(ctx.getDefaultListableBeanFactory());
        ctx.refresh();
        context = ctx;
        logger.info("*** Spring initialized!");
        PropertiesManager pm = context.getBean(PropertiesManager.class);
        pm.setProperties(props);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    logger.info("*** Basic configuration successful done.");
}