@Test public void testCreateApplicationContext() throws ConfigurationException, SpringHadoopAdminWorkflowException { ApplicationContext rootContext = null; try { rootContext = new ClassPathXmlApplicationContext(new String[] { "classpath:org/springframework/data/hadoop/admin/env-context.xml", "classpath:org/springframework/data/hadoop/admin/data-source-context.xml", "classpath:org/springframework/data/hadoop/admin/execution-context.xml", }); } catch (Exception e) { Assert.fail("test create root application context failed." + e.getMessage()); } try { JobRepository jobRepository = rootContext.getBean("jobRepository", JobRepository.class); if (jobRepository == null) { Assert.fail("test get JobRepository is null"); } } catch (Exception e) { Assert.fail("test get JobRepository failed." + e.getMessage()); } contextFactory.setApplicationContext(rootContext); File descriptor = new File("src/test/resources/org/springframework/data/hadoop/admin/workflow/support/context.xml"); File folder = descriptor.getParentFile(); HadoopWorkflowUtils.processUploadedFile(folder); ClassLoader loader = HadoopWorkflowUtils.getWorkflowClassLoader(folder); contextFactory.setBeanClassLoader(loader); contextFactory.setResource(new FileSystemResource( "src/test/resources/org/springframework/data/hadoop/admin/workflow/support/context.xml")); ConfigurableApplicationContext newContext = contextFactory.createApplicationContext(); logger.info("new context:" + newContext.toString()); Object obj = newContext.getBean("wordcount-withscript-job"); Assert.assertNotNull(obj); }
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; }
FileSystemApplicationContextFactory implements ApplicationContextFactory, ApplicationContextAware { 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; } }
FileSystemApplicationContextFactory implements ApplicationContextFactory, ApplicationContextAware { 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; } FileSystemApplicationContextFactory();  FileSystemApplicationContextFactory(Resource resource); }
FileSystemApplicationContextFactory implements ApplicationContextFactory, ApplicationContextAware { 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; } FileSystemApplicationContextFactory();  FileSystemApplicationContextFactory(Resource resource); void setResource(Resource resource); void setCopyConfiguration(boolean copyConfiguration); void setBeanFactoryPostProcessorClasses(Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses); void setBeanPostProcessorExcludeClasses(Class<?>[] beanPostProcessorExcludeClasses); void setApplicationContext(ApplicationContext applicationContext); ConfigurableApplicationContext createApplicationContext(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); ClassLoader getBeanClassLoader(); void setBeanClassLoader(ClassLoader beanClassLoader); }
FileSystemApplicationContextFactory implements ApplicationContextFactory, ApplicationContextAware { 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; } FileSystemApplicationContextFactory();  FileSystemApplicationContextFactory(Resource resource); void setResource(Resource resource); void setCopyConfiguration(boolean copyConfiguration); void setBeanFactoryPostProcessorClasses(Class<? extends BeanFactoryPostProcessor>[] beanFactoryPostProcessorClasses); void setBeanPostProcessorExcludeClasses(Class<?>[] beanPostProcessorExcludeClasses); void setApplicationContext(ApplicationContext applicationContext); ConfigurableApplicationContext createApplicationContext(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); ClassLoader getBeanClassLoader(); void setBeanClassLoader(ClassLoader beanClassLoader);  }