Example usage for org.springframework.batch.core.configuration.support ClassPathXmlApplicationContextFactory createApplicationContext

List of usage examples for org.springframework.batch.core.configuration.support ClassPathXmlApplicationContextFactory createApplicationContext

Introduction

In this page you can find the example usage for org.springframework.batch.core.configuration.support ClassPathXmlApplicationContextFactory createApplicationContext.

Prototype

@Override
public ConfigurableApplicationContext createApplicationContext() 

Source Link

Document

Creates an ApplicationContext from the provided path.

Usage

From source file:test.profile.ClassPathXmlJobRegistry.java

public void afterPropertiesSet() throws Exception {

    for (Resource resource : jobPaths) {
        ClassPathXmlApplicationContextFactory applicationContextFactory = new ClassPathXmlApplicationContextFactory();
        applicationContextFactory.setPath(resource);
        applicationContextFactory.setApplicationContext(parent);
        ApplicationContext context = applicationContextFactory.createApplicationContext();
        String[] names = context.getBeanNamesForType(Job.class);

        for (String name : names) {
            logger.debug("Registering job: " + name + " from context: " + resource);
            ApplicationContextJobFactory jobFactory = new ApplicationContextJobFactory(
                    applicationContextFactory, name);
            jobRegistry.register(jobFactory);
        }/*  w  w  w.j  av  a 2s  .  c  o  m*/
    }

    if (jobRegistry.getJobNames().isEmpty()) {
        throw new NoSuchJobException("Could not locate any jobs in resources provided.");
    }

}