Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#stop()
The following examples show how to use
org.springframework.context.support.ClassPathXmlApplicationContext#stop() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testAnnotation() { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); providerContext.start(); try { ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml"); consumerContext.start(); try { AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction"); String hello = annotationAction.doSayHello("world"); assertEquals("annotation: hello, world", hello); } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 2
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testSystemPropertyOverrideMultiProtocol() throws Exception { System.setProperty("dubbo.protocol.dubbo.port", "20814"); System.setProperty("dubbo.protocol.rmi.port", "10914"); ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/override-multi-protocol.xml"); providerContext.start(); try { ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo"); assertEquals(20814, dubbo.getPort().intValue()); ProtocolConfig rmi = (ProtocolConfig) providerContext.getBean("rmi"); assertEquals(10914, rmi.getPort().intValue()); } finally { System.setProperty("dubbo.protocol.dubbo.port", ""); System.setProperty("dubbo.protocol.rmi.port", ""); providerContext.stop(); providerContext.close(); } }
Example 3
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testInitReference() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml"); providerContext.start(); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml"); ctx.start(); try { DemoService demoService = (DemoService)ctx.getBean("demoService"); assertEquals("say:world", demoService.sayName("world")); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 4
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testInitReference() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml"); providerContext.start(); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml"); ctx.start(); try { DemoService demoService = (DemoService) ctx.getBean("demoService"); assertEquals("say:world", demoService.sayName("world")); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 5
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testDelayOnInitialized() throws Exception { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml"); //ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
Example 6
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void testInitReference() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml"); providerContext.start(); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml"); ctx.start(); try { DemoService demoService = (DemoService)ctx.getBean("demoService"); assertEquals("say:world", demoService.sayName("world")); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 7
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_returnSerializationFail() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-UnserializableBox.xml"); providerContext.start(); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml"); ctx.start(); try { DemoService demoService = (DemoService)ctx.getBean("demoService"); try { demoService.getBox(); fail(); } catch (RpcException expected) { assertThat(expected.getMessage(), containsString("must implement java.io.Serializable")); } } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 8
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testMultiProtocolRegister() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml"); ctx.start(); try { List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } }
Example 9
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testSystemPropertyOverrideXml() throws Exception { System.setProperty("dubbo.application.name", "sysover"); System.setProperty("dubbo.application.owner", "sysowner"); System.setProperty("dubbo.registry.address", "N/A"); System.setProperty("dubbo.protocol.name", "dubbo"); System.setProperty("dubbo.protocol.port", "20819"); System.setProperty("dubbo.service.register", "false"); ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override.xml"); providerContext.start(); try { ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig"); URL url = service.toUrls().get(0); assertEquals("sysover", url.getParameter("application")); assertEquals("sysowner", url.getParameter("owner")); assertEquals("dubbo", url.getProtocol()); assertEquals(20819, url.getPort()); String register = url.getParameter("register"); assertTrue(register != null && !"".equals(register)); assertEquals(false, Boolean.valueOf(register)); } finally { System.setProperty("dubbo.application.name", ""); System.setProperty("dubbo.application.owner", ""); System.setProperty("dubbo.registry.address", ""); System.setProperty("dubbo.protocol.name", ""); System.setProperty("dubbo.protocol.port", ""); System.setProperty("dubbo.service.register", ""); providerContext.stop(); providerContext.close(); } }
Example 10
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testMultiProtocolDefault() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml"); ctx.start(); try { DemoService demoService = refer("rmi://127.0.0.1:10991"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } }
Example 11
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testSystemPropertyOverrideXml() throws Exception { System.setProperty("dubbo.application.name", "sysover"); System.setProperty("dubbo.application.owner", "sysowner"); System.setProperty("dubbo.registry.address", "N/A"); System.setProperty("dubbo.protocol.name", "dubbo"); System.setProperty("dubbo.protocol.port", "20819"); System.setProperty("dubbo.service.register", "false"); ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override.xml"); providerContext.start(); try { ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig"); URL url = service.toUrls().get(0); assertEquals("sysover", url.getParameter("application")); assertEquals("sysowner", url.getParameter("owner")); assertEquals("dubbo", url.getProtocol()); assertEquals(20819, url.getPort()); String register = url.getParameter("register"); assertTrue(register != null && !"".equals(register)); assertEquals(false, Boolean.valueOf(register)); } finally { System.setProperty("dubbo.application.name", ""); System.setProperty("dubbo.application.owner", ""); System.setProperty("dubbo.registry.address", ""); System.setProperty("dubbo.protocol.name", ""); System.setProperty("dubbo.protocol.port", ""); System.setProperty("dubbo.service.register", ""); providerContext.stop(); providerContext.close(); } }
Example 12
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void test_RpcContext_getUrls() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml"); providerContext.start(); try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference-getUrls.xml"); ctx.start(); try { DemoService demoService = (DemoService) ctx.getBean("demoService"); try { demoService.sayName("Haha"); fail(); } catch (RpcException expected) { assertThat(expected.getMessage(), containsString("Tried 3 times")); } assertEquals(3, RpcContext.getContext().getUrls().size()); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } }
Example 13
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void test_noMethodInterface_methodsKeyHasValue() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-no-methods-interface.xml"); ctx.start(); try { ServiceBean bean = (ServiceBean) ctx.getBean("service"); List<URL> urls = bean.getExportedUrls(); assertEquals(1, urls.size()); URL url = urls.get(0); assertEquals("sayName,getBox", url.getParameter("methods")); } finally { ctx.stop(); ctx.close(); } }
Example 14
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServiceClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml"); ctx.start(); try { DemoService demoService = refer("dubbo://127.0.0.1:20887"); String hello = demoService.sayName("hello"); assertEquals("welcome:hello", hello); } finally { ctx.stop(); ctx.close(); } }
Example 15
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testMultiProtocolDefault() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml"); ctx.start(); try { DemoService demoService = refer("rmi://127.0.0.1:10991"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } }
Example 16
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testMultiProtocolError() { try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-error.xml"); ctx.start(); ctx.stop(); ctx.close(); } catch (BeanCreationException e) { assertTrue(e.getMessage().contains("Found multi-protocols")); } }
Example 17
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testServiceClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml"); ctx.start(); try { DemoService demoService = refer("dubbo://127.0.0.1:20887"); String hello = demoService.sayName("hello"); assertEquals("welcome:hello", hello); } finally { ctx.stop(); ctx.close(); } }
Example 18
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testSystemPropertyOverrideXmlDefault() throws Exception { System.setProperty("dubbo.application.name", "sysover"); System.setProperty("dubbo.application.owner", "sysowner"); System.setProperty("dubbo.registry.address", "N/A"); System.setProperty("dubbo.protocol.name", "dubbo"); System.setProperty("dubbo.protocol.port", "20819"); ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override-default.xml"); providerContext.start(); try { ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig"); assertEquals("sysover", service.getApplication().getName()); assertEquals("sysowner", service.getApplication().getOwner()); assertEquals("N/A", service.getRegistry().getAddress()); assertEquals("dubbo", service.getProtocol().getName()); assertEquals(20819, service.getProtocol().getPort().intValue()); } finally { System.setProperty("dubbo.application.name", ""); System.setProperty("dubbo.application.owner", ""); System.setProperty("dubbo.registry.address", ""); System.setProperty("dubbo.protocol.name", ""); System.setProperty("dubbo.protocol.port", ""); providerContext.stop(); providerContext.close(); } }
Example 19
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testMultiProtocol() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml"); ctx.start(); try { DemoService demoService = refer("dubbo://127.0.0.1:20881"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } }
Example 20
Source File: SimpeTestNode_2.java From uncode-schedule with Apache License 2.0 | 3 votes |
public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml"); Thread.sleep(30 * 1000); context.stop(); context.close(); System.exit(0); }