Example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:com.alibaba.dubbo.examples.merge.MergeConsumer.java

public static void main(String[] args) throws Exception {
    String config = MergeConsumer.class.getPackage().getName().replace('.', '/') + "/merge-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/* ww  w. jav  a  2  s .  c  om*/
    MergeService mergeService = (MergeService) context.getBean("mergeService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        try {
            List<String> result = mergeService.mergeResult();
            System.out.println("(" + i + ") " + result);
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.alibaba.dubbo.examples.merge.MergeConsumer2.java

public static void main(String[] args) throws Exception {
    String config = MergeConsumer2.class.getPackage().getName().replace('.', '/') + "/merge-consumer2.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/*from  w ww .ja v a2  s. c  om*/
    MergeService mergeService = (MergeService) context.getBean("mergeService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        try {
            List<String> result = mergeService.mergeResult();
            System.out.println("(" + i + ") " + result);
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.alibaba.dubbo.examples.callback.CallbackConsumer.java

public static void main(String[] args) throws Exception {
    String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/* w w w .  j a  v  a 2s  . c  om*/
    CallbackService callbackService = (CallbackService) context.getBean("callbackService");
    callbackService.addListener("foo.bar", new CallbackListener() {
        public void changed(String msg) {
            System.out.println("callback1:" + msg);
        }
    });
    System.in.read();
}

From source file:sk.stefan.projekt.trial.ABapp.java

public static void main(String[] args) throws Exception {

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/context/TrialContext.xml");

    ABapp aba = (ABapp) ctx.getBean("abApp");

    aba.tryFactory();//from  w w w .  ja  v a2  s.c  om

}

From source file:demo.spring.client.Client.java

public static void main(String args[]) throws Exception {
    // START SNIPPET: client
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "client-beans.xml" });

    HelloWorld client = (HelloWorld) context.getBean("client");

    String response = client.sayHi("Joe");
    System.out.println("Response: " + response);
    System.exit(0);/* ww  w. j  av  a  2  s. c om*/
    // END SNIPPET: client
}

From source file:com.alibaba.dubbo.examples.annotation.AnnotationConsumer.java

public static void main(String[] args) throws Exception {
    String config = AnnotationConsumer.class.getPackage().getName().replace('.', '/')
            + "/annotation-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//w  w  w .j a  va  2  s  .c  o  m
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
    System.in.read();
}

From source file:com.apress.prospringintegration.App.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
    context.start();/*from  w w  w . j a  v a2s.c o  m*/

    MessageChannel input = (MessageChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    input.send(MessageBuilder.withPayload("Pro Spring Integration Example").build());
    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:com.github.cmis4j.ws.CmisRepositoryMain.java

@SuppressWarnings("unused")
public static void main(String[] args) {
    try {/*from ww w  .j av a  2 s . com*/
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("cmis4j-ws-test.xml");
        ACLServicePort aclService = (ACLServicePort) ctx.getBean("aclService");
        DiscoveryServicePort discoveryService = (DiscoveryServicePort) ctx.getBean("discoveryService");
        MultiFilingServicePort multiFilingService = (MultiFilingServicePort) ctx.getBean("multiFilingService");
        NavigationServicePort navigationService = (NavigationServicePort) ctx.getBean("navigationService");
        ObjectServicePort objectService = (ObjectServicePort) ctx.getBean("objectService");
        PolicyServicePort policyService = (PolicyServicePort) ctx.getBean("policyService");
        RelationshipServicePort relationshipService = (RelationshipServicePort) ctx
                .getBean("relationshipService");
        RepositoryServicePort repositoryService = (RepositoryServicePort) ctx.getBean("repositoryService");
        VersioningServicePort versioningService = (VersioningServicePort) ctx.getBean("versioningService");
        ctx.close();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:hu.vanio.jms.spring3.ibmmq.Start.java

public static void main(String[] args) throws IOException, InterruptedException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/application.xml");

    // sending messages
    JmsQueueSender jqs = ctx.getBean(JmsQueueSender.class);
    String message = "Hello queue world!"
            + " National chars (see CCSID): \"--\"''<>&@# AE: ";

    // send five message and sleep half second
    for (int i = 1; i <= 5; i++) {
        Thread.sleep(500);/*  w  w w .  ja v  a 2  s.c  om*/
        jqs.simpleSend(i + ". " + message);
    }

    // quit after 1 second
    Thread.sleep(1000);
    ctx.destroy();
}

From source file:com.alibaba.dubbo.examples.redis.RedisConsumer.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String config = RedisConsumer.class.getPackage().getName().replace('.', '/') + "/redis-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/*from  w  w  w.j a va2  s .c  om*/
    Map<String, Object> cache = (Map<String, Object>) context.getBean("cache");
    cache.remove("hello");
    Object value = cache.get("hello");
    System.out.println(value);
    if (value != null) {
        throw new IllegalStateException(value + " != null");
    }
    cache.put("hello", "world");
    value = cache.get("hello");
    System.out.println(value);
    if (!"world".equals(value)) {
        throw new IllegalStateException(value + " != world");
    }
}