public static void main(String[] args) { List<String> languages = Arrays.asList(new String[]{"groovy","ruby","javascript","python"}); if (args.length != 1) { usage(); } String lang = args[0]; if (!StringUtils.hasText(lang)){ usage(); } lang = lang.toLowerCase(); if (!languages.contains(lang)){ usage(); } /* * Create an application context and set the active profile to configure the * corresponding scripting implementation */ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(); ctx.getEnvironment().setActiveProfiles(lang); ctx.setConfigLocation("/META-INF/spring/integration/cafeDemo.xml"); ctx.refresh(); }
@Test public void testAllowBeanOverride() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setConfigLocation("org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml"); applicationContext.refresh(); }
@Test public void testAllowBeanOverrideFalse() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setAllowBeanDefinitionOverriding(false); applicationContext.setConfigLocation("org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml"); applicationContext.refresh(); } }
@Test public void registerDataValueProcessorOnlyIfNotRegistered() throws Exception { try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext()) { context.setAllowBeanDefinitionOverriding(false); context.setConfigLocation(this.xml("RegisterDataValueProcessorOnyIfNotRegistered")); context.refresh(); } }
@Test public void testRemoteChunkingMasterReplyChannelAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingReplyChannelAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The reply-channel attribute must be specified" + " but got: " + iae.getMessage(), "The reply-channel attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingSlaveItemWriterAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingItemWriterAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The item-writer attribute must be specified" + " but got: " + iae.getMessage(), "The item-writer attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingSlaveIdAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingIdAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(), "The id attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingMasterIdAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingIdAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(), "The id attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingSlaveOutputChannelAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingOutputChannelAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The output-channel attribute must be specified" + " but got: " + iae.getMessage(), "The output-channel attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingSlaveInputChannelAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingInputChannelAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The input-channel attribute must be specified" + " but got: " + iae.getMessage(), "The input-channel attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingMasterMessageTemplateAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingMessageTemplateAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The message-template attribute must be specified" + " but got: " + iae.getMessage(), "The message-template attribute must be specified".equals(iae.getMessage())); } }
@Test public void testRemoteChunkingMasterStepAttrAssert() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setValidating(false); applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingStepAttrTests.xml"); try { applicationContext.refresh(); fail(); } catch (BeanDefinitionStoreException e) { assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); IllegalArgumentException iae = (IllegalArgumentException) e.getCause(); assertTrue("Expected: " + "The step attribute must be specified" + " but got: " + iae.getMessage(), "The step attribute must be specified".equals(iae.getMessage())); } }
private ClassPathXmlApplicationContext createContext(UdpUnicastEndToEndTests launcher, String location) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setConfigLocation(location); StandardEnvironment env = new StandardEnvironment(); Properties props = new Properties(); props.setProperty("port", Integer.toString(launcher.getReceiverPort())); PropertiesPropertySource pps = new PropertiesPropertySource("ftpprops", props); env.getPropertySources().addLast(pps); applicationContext.setEnvironment(env); applicationContext.refresh(); return applicationContext; }
private ClassPathXmlApplicationContext createContext(UdpMulticastEndToEndTests launcher, String location) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(); applicationContext.setConfigLocation(location); StandardEnvironment env = new StandardEnvironment(); Properties props = new Properties(); props.setProperty("port", Integer.toString(launcher.getReceiverPort())); PropertiesPropertySource pps = new PropertiesPropertySource("ftpprops", props); env.getPropertySources().addLast(pps); applicationContext.setEnvironment(env); applicationContext.refresh(); return applicationContext; }
assertEquals(2, evalContexts.size()); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(parent); child.setConfigLocation("org/springframework/integration/expression/ChildContext-context.xml"); child.refresh();
public static void main(String[] args) { // 构建 XML 配置驱动 Spring 上下文 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); // 设置 XML 配置文件的位置 context.setConfigLocation("classpath:/META-INF/spring/context.xml"); // 启动上下文 context.refresh(); // 获取名称为 "chineseNameRepository" Bean 对象 NameRepository nameRepository = (NameRepository) context.getBean("chineseNameRepository"); // 输出用户名称:[张三, 李四, 小马哥] System.out.printf("nameRepository.findAll() = %s \n", nameRepository.findAll()); } }
public static KieModuleModel fromXML(File kModuleFile, ReleaseId releaseId){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(kModuleFile.getAbsolutePath()); context.setConfigLocation(kModuleFile.getAbsolutePath()); context.refresh(); context.registerShutdownHook(); return null;//kieSpringApplicationListener.getKieModuleModel(); }
public static KieModuleModel fromXML(File kModuleFile, ReleaseId releaseId){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(kModuleFile.getAbsolutePath()); context.setConfigLocation(kModuleFile.getAbsolutePath()); context.refresh(); context.registerShutdownHook(); return null;//kieSpringApplicationListener.getKieModuleModel(); }
public static KieModuleModel fromXML(java.net.URL kModuleUrl, ReleaseId releaseId){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); KModuleBeanFactoryPostProcessor beanFactoryPostProcessor = new KModuleBeanFactoryPostProcessor(kModuleUrl, context); beanFactoryPostProcessor.setReleaseId(releaseId); context.addBeanFactoryPostProcessor(beanFactoryPostProcessor); context.setConfigLocation(kModuleUrl.toExternalForm()); context.refresh(); context.registerShutdownHook(); return null;//kieSpringApplicationListener.getKieModuleModel(); }
public static KieModuleModel fromXML(java.net.URL kModuleUrl, ReleaseId releaseId){ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); KModuleBeanFactoryPostProcessor beanFactoryPostProcessor = new KModuleBeanFactoryPostProcessor(kModuleUrl, context); beanFactoryPostProcessor.setReleaseId(releaseId); context.addBeanFactoryPostProcessor(beanFactoryPostProcessor); context.setConfigLocation(kModuleUrl.toExternalForm()); context.refresh(); context.registerShutdownHook(); return null;//kieSpringApplicationListener.getKieModuleModel(); }