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

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

Introduction

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

Prototype

public FileSystemXmlApplicationContext(String... configLocations) throws BeansException 

Source Link

Document

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Usage

From source file:org.activiti.crystalball.anttasks.GenerateGraphTask.java

public void execute() {

    log("Starting generator [" + generatorBean + "] from application context [" + appContext + "].",
            Project.MSG_INFO);/* w  w  w.  j  a v a  2  s  . c o  m*/

    // seting app context
    if (appContext == null) {
        throw new BuildException("No application context set.");
    }
    FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(appContext);
    try {
        // getting generator
        AbstractProcessEngineGraphGenerator generator = null;
        if (generatorBean != null)
            generator = (AbstractProcessEngineGraphGenerator) applicationContext.getBean(generatorBean);
        if (generator == null) {
            applicationContext.close();
            throw new BuildException("unable to get generator bean");
        }

        // running report generate
        try {
            generator.generateReport(processDefinitionId, getStartDate(), getEndDate(), reportFileName);
        } catch (IOException e) {
            log("Generator exception", Project.MSG_ERR);
            throw new BuildException(e);
        } catch (ParseException e) {
            log("Generator exception - parsing dates", Project.MSG_ERR);
            throw new BuildException(e);
        }
    } finally {
        applicationContext.close();
    }

    log("Generator [" + generatorBean + "] execution from application context [" + appContext + "] done.",
            Project.MSG_INFO);
}

From source file:cn.vlabs.umt.ui.UMTStartupListener.java

public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    PropertyConfigurator.configure(context.getRealPath("/WEB-INF/conf/log4j.properties"));
    String contextxml = context.getInitParameter("contextConfigLocation");
    if (contextxml == null) {
        contextxml = "/WEB-INF/conf/UMTContext.xml";
    }//  www. j  a v  a2 s  . c o  m
    //FIX the bug in linux
    String realpath = context.getRealPath(contextxml);
    if (realpath != null && realpath.startsWith("/")) {
        realpath = "/" + realpath;
    }
    FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext(realpath);
    PathMapper mapper = (PathMapper) factory.getBean("PathMapper");
    mapper.setContext(context);

    CreateTable createTable = (CreateTable) factory.getBean("CreateTable");
    if (!createTable.isTableExist()) {
        createTable.createTable();
    }
    factory.getBean("UMTCredUtil");
    context.setAttribute(Attributes.APPLICATION_CONTEXT_KEY, factory);
    UMTContext.setFactory(factory);

}

From source file:org.gallery.persist.ImageDaoTest.java

@Before
public void setUp() throws DatabaseUnitException, SQLException, IOException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = loader.getResource(jsonfilename);
    file = new File(url.getFile());

    ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext-test.xml");
    Connection connection = DataSourceUtils.getConnection((DataSource) ctx.getBean("dataSource"));
    DatabaseConnection dbunitConnection = new DatabaseConnection(connection, null);
    IDataSet expectedDataSet = getDataSet("data-test/full-database.xml");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitConnection, expectedDataSet);
    imageDao = ctx.getBean(ImageDao.class);
}

From source file:pt.webdetails.cpf.SpringEnabledContentGenerator.java

private ConfigurableApplicationContext getSpringBeanFactory() {
    final PluginClassLoader loader = (PluginClassLoader) pm.getClassLoader(getPluginName());
    logger.warn(loader.getPluginDir());/*from   ww w  . jav  a 2  s.  c  o  m*/
    File f = new File(loader.getPluginDir(), "plugin.spring.xml"); //$NON-NLS-1$
    if (f.exists()) {
        logger.debug("Found plugin spring file @ " + f.getAbsolutePath()); //$NON-NLS-1$
        ConfigurableApplicationContext context = new FileSystemXmlApplicationContext(
                "file:" + f.getAbsolutePath()) { //$NON-NLS-1$
            @Override
            protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {

                beanDefinitionReader.setBeanClassLoader(loader);
            }

            @Override
            protected void prepareBeanFactory(ConfigurableListableBeanFactory clBeanFactory) {
                super.prepareBeanFactory(clBeanFactory);
                clBeanFactory.setBeanClassLoader(loader);
            }

            /**
             * Critically important to override this and return the desired
             * CL
            *
             */
            @Override
            public ClassLoader getClassLoader() {
                return loader;
            }
        };
        return context;
    }
    throw new IllegalStateException("no plugin.spring.xml file found"); //$NON-NLS-1$
}

From source file:net.kamhon.ieagle.application.Application.java

protected static synchronized ApplicationContext initialize(final ServletContext servletContext) {
    try {/*from w  ww.j  a  va 2s  . c o m*/
        if (appContext == null) {
            appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        }
    } catch (Exception ex) {
        log.info("WebApplicationContext not found!!! Using ClassPathXmlApplicationContext");

        if (StringUtils.isBlank(contextPath)) {
            initContextPath();
        }

        try {
            if (appContext == null && contextPath.endsWith(".class")) {
                appContext = new AnnotationConfigApplicationContext(
                        Class.forName(contextPath.substring(0, contextPath.length() - ".class".length())));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            if (appContext == null)
                appContext = new FileSystemXmlApplicationContext(contextPath);
        } catch (Exception e) {
        }

        try {
            if (appContext == null)
                appContext = new ClassPathXmlApplicationContext(contextPath);
        } catch (Exception e) {
        }

        createGenericApplicationContext();
    }

    return appContext;
}

From source file:org.jbpm.formbuilder.server.RESTFileServiceTest.java

public void testSetContextOK() throws Exception {
    RESTFileService restService = new RESTFileService();
    URL pathToClasses = getClass().getResource("/FormBuilder.properties");
    String filePath = pathToClasses.toExternalForm();
    //assumes compilation is in target/classes
    filePath = filePath.replace("target/classes/FormBuilder.properties", "src/main/webapp");
    filePath = filePath + "/WEB-INF/springComponents.xml";
    FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(filePath);
    ServiceFactory.getInstance().setBeanFactory(ctx);
    ServletContext context = EasyMock.createMock(ServletContext.class);

    EasyMock.replay(context);//from   www .ja  va 2 s  .  com
    restService.setContext(context);
    EasyMock.verify(context);

    FileService service = restService.getFileService();
    assertNotNull("service shouldn't be null", service);
}

From source file:com.intertech.tests.ServiceTest.java

/**
 * Test contact service.//ww  w .  j av a 2 s  . c  om
 */
public static void testContactService() {
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
            new String[] { "spring-beans.xml", "test-beans.xml" });
    context.registerShutdownHook();
    ContactList list = context.getBean("testList", ContactList.class);
    ContactService service = context.getBean("contactService", ContactService.class);
    List<Contact> contacts = list.getContacts();
    for (Contact contact : contacts) {
        service.addContact(contact);
        System.out.println("Test: " + contact + " was added to the Contact DB");
    }
    System.out.println("Test: Married contacts:  " + marriedContacts(contacts));
}

From source file:org.bigtester.ate.TestProjectRunner.java

/**
 * Run test./*w ww  .j a  va 2  s.c  o m*/
 *
 * @param testProjectXml the test project xml
 * @throws DatabaseUnitException the database unit exception
 * @throws SQLException the SQL exception
 * @throws IOException 
 * @throws ClassNotFoundException 
 * @throws ParseException 
 */
public static void runTest(@Nullable final String testProjectXml)
        throws DatabaseUnitException, SQLException, IOException, ClassNotFoundException, ParseException {
    ApplicationContext context;
    if (StringUtils.isEmpty(testProjectXml)) {
        context = new ClassPathXmlApplicationContext("testproject.xml");
    } else {
        context = new FileSystemXmlApplicationContext(testProjectXml);

    }

    TestProject testplan = GlobalUtils.findTestProjectBean(context);
    testplan.setAppCtx(context);

    TestDatabaseInitializer dbinit = (TestDatabaseInitializer) context
            .getBean(GlobalConstants.BEAN_ID_GLOBAL_DBINITIALIZER);

    dbinit.setSingleInitXmlFile(testplan.getGlobalInitXmlFile());

    //TODO add db initialization handler
    dbinit.initializeGlobalDataFile(context);

    runTest(context);

    ((ConfigurableApplicationContext) context).close();
}

From source file:com.nabla.project.application.core.log.LogCustomTest.java

/**
 * DOCUMENT ME!//from w w  w .  j  a  v a  2  s .  c  o m
 * 
 * @throws Exception DOCUMENT ME!
 */
public void testLog() throws Exception {

    if (logger.isDebugEnabled()) {
        logger.debug("testLog");
    }

    ApplicationContext ctx = new FileSystemXmlApplicationContext(
            "src/test/java/com/nabla/project/application/core/log/LogCustom.xml");
    Log4JLogger commonlogger = (Log4JLogger) ctx.getBean("loggingfactorybean");

    if (commonlogger.isDebugEnabled()) {
        commonlogger.debug("Common logger is enable");
    }

    Log.setCommonlogger(commonlogger);

    if (Log.getCommonlogger().isDebugEnabled()) {
        Log.getCommonlogger().debug("mylogger 1 - DEBUG - should not be print");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("rootLogger 1 - DEBUG - should not be print");
    }

    Log.getCommonlogger().warn("mylogger 3 - WARNING");
    logger.warn("rootLogger 1 - WARNING - should not be print");
    Log.getCommonlogger().info("mylogger 2 - INFO - should not be print");
    logger.info("rootLogger 1 - INFO - should not be print");
    Log.getCommonlogger().error("mylogger 4 - ERROR");
    logger.error("rootLogger 4 - ERROR - should not be print");
    Log.getCommonlogger().fatal("mylogger 5 - FATAL");
    logger.fatal("rootLogger 5 - FATAL");

    Thread.sleep(5000L);

}

From source file:net.sourceforge.happybank.main.BankMain.java

/**
 * default constructor/*from   www . java  2s . c  om*/
 */
public BankMain() {
    // get context and facade
    ApplicationContext ctx = new FileSystemXmlApplicationContext("applicationContext.xml");
    bank = (BankingFacade) ctx.getBean("bankManager");
    initComponents();
    frame.pack();
}