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() 

Source Link

Document

Create a new FileSystemXmlApplicationContext for bean-style configuration.

Usage

From source file:net.phoenix.thrift.server.Server.java

/**
 * ? spring?//from www .j ava 2  s.com
 * @param args
 * @throws Exception
 */
public static int main(String[] args) throws Exception {
    if (args.length == 0 || StringUtils.isEmpty(args[0])) {
        LOG.error("Please assign spring configuration file . ");
        return 0;
    }
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext();
    context.setConfigLocation(args[0]);
    context.registerShutdownHook();
    context.refresh();
    context.close();
    return 1;
}

From source file:natalia.dymnikova.cluster.UnitTestTcpTransportAddressStealerExtensionIdTest.java

@Before
public void setUp() throws Exception {
    SpringActorProducer.initialize(new FileSystemXmlApplicationContext());
}

From source file:com.github.mjeanroy.springmvc.view.mustache.configuration.AbstractMustacheConfiguration.java

/**
 * Get active resource loader.//w ww  .ja va  2s.  com
 * The default implementation is to return a set of resource loaders.
 *
 * @return Resource loader.
 */
protected ResourceLoader getResourceLoader() {
    List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>();

    if (resourceLoader != null) {
        resourceLoaders.add(resourceLoader);
    }

    if (applicationContext != null) {
        resourceLoaders.add(applicationContext);
    }

    if (resourceLoaders.isEmpty()) {
        resourceLoaders.add(new ClassPathXmlApplicationContext());
        resourceLoaders.add(new FileSystemXmlApplicationContext());
    }

    log.debug("Create resource loader using: {}", resourceLoaders);

    return new CompositeResourceLoader(resourceLoaders);
}

From source file:com.github.mjeanroy.springmvc.view.mustache.configuration.MustacheTemplateLoaderFactoryBean.java

protected ResourceLoader computeResourceLoader() {
    log.debug("Build composite resource loader");
    Collection<ResourceLoader> resourceLoaders = new LinkedHashSet<ResourceLoader>();

    if (resourceLoader != null) {
        log.trace(" => Add custom resource loader: {}", resourceLoader);
        resourceLoaders.add(resourceLoader);
    }//from  www  .j a v a2 s .c om

    if (applicationContext != null) {
        log.trace(" => Add application context as resource loader: {}", applicationContext);
        resourceLoaders.add(applicationContext);
    }

    if (resourceLoaders.isEmpty()) {
        log.trace(" => Add instance of ClassPathXmlApplicationContext as resource loader");
        resourceLoaders.add(new ClassPathXmlApplicationContext());

        log.trace(" => Add instance of FileSystemXmlApplicationContext as resource loader");
        resourceLoaders.add(new FileSystemXmlApplicationContext());
    }

    log.debug("Add instance of classpath resource loader");
    resourceLoaders.add(CLASSPATH_RESOURCE_LOADER);

    log.debug("Create composite resource loader using: {}", resourceLoaders);
    log.trace(" => Number of loaders: {}", resourceLoaders.size());
    return new CompositeResourceLoader(resourceLoaders);
}

From source file:com.browseengine.bobo.api.BoboIndexReader.java

private static Collection<FacetHandler<?>> loadFromIndex(File file, WorkArea workArea) throws IOException {
    // File springFile = new File(file, SPRING_CONFIG);
    // FileSystemXmlApplicationContext appCtx =
    //   new FileSystemXmlApplicationContext("file:" + springFile.getAbsolutePath());
    //return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");

    Set<Entry<Class<?>, Object>> entries = workArea.map.entrySet();
    FileSystemXmlApplicationContext appCtx = new FileSystemXmlApplicationContext();
    for (Entry<Class<?>, Object> entry : entries) {
        Object obj = entry.getValue();
        if (obj instanceof ClassLoader) {
            appCtx.setClassLoader((ClassLoader) obj);
            break;
        }/*w  ww . j a va2s. c o m*/
    }

    String absolutePath = file.getAbsolutePath();
    String partOne = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
    String partTwo = URLEncoder.encode(absolutePath.substring(absolutePath.lastIndexOf(File.separator) + 1),
            "UTF-8");
    absolutePath = partOne + File.separator + partTwo;

    File springFile = new File(new File(absolutePath), SPRING_CONFIG);
    appCtx.setConfigLocation("file:" + springFile.getAbsolutePath());
    appCtx.refresh();

    return (Collection<FacetHandler<?>>) appCtx.getBean("handlers");

}

From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowUtils.java

/**
 * create and register Spring Batch job//from   w  w  w . ja  v  a 2 s .c  o  m
 * 
 * @param context root application context
 * @param artifacts workflow artifacts which include workflow descriptor and class loader information.
 * @throws Exception
 */
public static void createAndRegisterSpringBatchJob(ApplicationContext context,
        final WorkflowArtifacts artifacts) throws SpringHadoopAdminWorkflowException {
    if (context == null) {
        logger.warn("root applicaton context is null");
        throw new SpringHadoopAdminWorkflowException("root applicaton context is null");
    }
    String workflowDescriptor = getWorkflowDescriptor(artifacts);
    logger.info("create spring batch job:" + workflowDescriptor + ", classloader:"
            + artifacts.getWorkflowClassLoader());

    final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext();
    ctx.setClassLoader(artifacts.getWorkflowClassLoader());
    ctx.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + workflowDescriptor);

    try {
        SimpleJob job = new SimpleJob(generateSpringBatchJobName(artifacts));
        TaskletStep step = new TaskletStep(springHadoopTaskName);
        SimpleSpringHadoopTasklet tasklet = new SimpleSpringHadoopTasklet();
        tasklet.setContext(ctx);
        step.setTasklet(tasklet);
        JobRepository jobRepository = context.getBean(JobRepository.class);
        DataSourceTransactionManager transactionManager = context.getBean("transactionManager",
                DataSourceTransactionManager.class);
        step.setTransactionManager(transactionManager);
        step.setJobRepository(jobRepository);
        step.afterPropertiesSet();
        job.addStep(step);
        JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
        job.setJobRepository(jobRepository);
        job.afterPropertiesSet();
        JobFactory jobFactory = new ReferenceJobFactory(job);
        jobRegistry.register(jobFactory);
    } catch (Exception e) {
        logger.warn("create and register Spring Batch Job failed");
        throw new SpringHadoopAdminWorkflowException("create and register Spring Batch Job failed", e);
    }
}

From source file:org.springframework.data.hadoop.admin.workflow.support.FileSystemApplicationContextFactory.java

/**
 * Creates an {@link ApplicationContext} from the provided path.
 * //from   w w  w  .  j a  v a2 s.  c  om
 * @see ApplicationContextFactory#createApplicationContext()
 */
public ConfigurableApplicationContext createApplicationContext() {
    logger.info("resource is:" + resource);
    if (resource == null) {
        return parent;
    }
    try {
        logger.info("create application context, resource:" + resource.getFile().getAbsolutePath()
                + ", classloader:" + this.beanClassLoader + ". Parent is:" + parent);
        FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext();
        context.setClassLoader(this.beanClassLoader);
        context.setParent(parent);
        context.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + resource.getFile().getAbsolutePath());
        context.refresh();
        return context;
    } catch (Exception e) {
        try {
            logger.error(
                    "create application context fail. with resource:" + resource.getFile().getAbsolutePath(),
                    e);
        } catch (IOException e1) {
            logger.error("log error", e1);
        }
    }
    return parent;
}