Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#destroy()

The following examples show how to use org.springframework.context.support.ClassPathXmlApplicationContext#destroy() . 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: ThriftConsumerMultiApi.java    From octo-rpc with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/multiport/thrift-consumer-multiapi.xml");

        HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
        System.out.println(userService.sayHello("Emma"));

        Echo.Iface echo = (Echo.Iface) beanFactory.getBean("echoService");
        System.out.println(echo.echo("Hello world"));

        beanFactory.destroy();
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL) serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 3
Source File: ThriftConsumer.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/zkmock/thrift-consumer.xml");

        HelloService.Iface userservice = (HelloService.Iface) beanFactory.getBean("helloService");
        System.out.println(userservice.sayHello("Emma"));

        beanFactory.destroy();
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: MultiRoleService.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/multirole/thrift-multiroles.xml");

        HelloService.Iface userservice = (HelloService.Iface) beanFactory.getBean("helloService");
        System.out.println(userservice.sayHello("Emma"));

        beanFactory.destroy();
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: ThriftConsumer.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/simple/thrift-consumer.xml");

        HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
        System.out.println(userService.sayHello("OCTO"));

        beanFactory.destroy();
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: ThriftConsumer.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/zkregistry/thrift-consumer.xml");

        HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
        System.out.println(userService.sayHello("Emma"));

        beanFactory.destroy();
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: DoradoDemo.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TException, InterruptedException, IOException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
    final Echo.Iface client = context.getBean("clientProxy", Echo.Iface.class);

    Thread[] threads = new Thread[num];

    for (int i = 0; i < num; i++) {
        final int finalI = i;
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                String result = null;
                Random random = new Random();
                for (int j = 0; j < num; j++) {
                    try {
                        result = client.echo("hello" + finalI + "," + j);
                        Thread.sleep(random.nextInt(100));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    assert ("echo: hello" + finalI + "," + j).equals(result);
                }
            }
        });
        threads[i].start();
    }

    for (Thread t : threads) {
        t.join();
    }

    context.destroy();
    System.exit(0);
}
 
Example 8
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 9
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 10
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 11
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 12
Source File: SpringBeanExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws Exception If example execution failed.
 */
public static void main(String[] args) throws Exception {
    System.out.println();
    System.out.println(">>> Spring bean example started.");

    // Initialize Spring factory.
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext("org/apache/ignite/examples/misc/springbean/spring-bean.xml");

    try {
        // Get ignite from Spring (note that local cluster node is already started).
        Ignite ignite = (Ignite)ctx.getBean("mySpringBean");

        // Execute any method on the retrieved ignite instance.
        ExecutorService exec = ignite.executorService();

        Future<String> res = exec.submit(new Callable<String>() {
            @Override public String call() throws Exception {
                System.out.println("Hello world!");

                return null;
            }
        });

        // Wait for callable completion.
        res.get();

        System.out.println(">>>");
        System.out.println(">>> Finished executing Ignite \"Spring bean\" example.");
        System.out.println(">>> You should see printed out of 'Hello world' on one of the nodes.");
        System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
        System.out.println(">>>");
    }
    finally {
        // Stop local cluster node.
        ctx.destroy();
    }
}
 
Example 13
Source File: SpringExample.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   System.out.println("Creating bean factory...");
   ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring-jms-beans.xml"});
   MessageSender sender = (MessageSender) context.getBean("MessageSender");
   System.out.println("Sending message...");
   sender.send("Hello world");
   Thread.sleep(100);
   context.destroy();
}
 
Example 14
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
Example 15
Source File: InitDestroyExample.java    From java-course-ee with MIT License 3 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"springContext.xml"});

    log.debug("\n\n\n");

    Thread.sleep(5000);

    log.debug("Destroying context...");
    context.destroy();
}