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:andy.zhang.dubbo.consumer.AppClient.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "applicationConsumer.xml" });
    context.start();//from w  w w .ja v a2 s. c o m
    IProcessData demoService = (IProcessData) context.getBean("demoService");
    System.out.println(demoService.hello("world "));
}

From source file:com.apress.prospringintegration.channels.rendezvouschannel.Main.java

public static void main(String[] args) throws Throwable {
    String contextName = "rendezvous-channel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();// ww w.  jav  a  2s. c o  m

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketReceiver ticketReceiver = applicationContext.getBean(TicketReceiver.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);

    // start *before* message publication because it'll block on put
    Thread consumerThread = new Thread(ticketReceiver);
    consumerThread.start();

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }
}

From source file:com.apress.prospringintegration.messaging.activemq.jms.backedchannel.TicketMain.java

public static void main(String[] args) {

    String contextName = "jms-backedchannel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//from   w  ww  . j  a  va2s. c  om

    TicketCreator ticketCreator = applicationContext.getBean(TicketCreator.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);

    SubscribableChannel channel = applicationContext.getBean("ticketChannel", SubscribableChannel.class);
    channel.subscribe(ticketMessageHandler);

    while (true) {
        List<Ticket> tickets = ticketGenerator.createTickets();
        for (Ticket ticket : tickets) {
            ticketCreator.openTicket(ticket);
        }
    }
}

From source file:com.apress.prospringintegration.channels.directchannel.Main.java

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

    String contextName = "direct-channel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();// ww  w  .  j  a va 2  s  .  c o m

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);

    DirectChannel channel = applicationContext.getBean("ticketChannel", DirectChannel.class);
    channel.subscribe(ticketMessageHandler);

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }
}

From source file:com.apress.prospringintegration.channels.executorchannel.Main.java

public static void main(String[] args) {
    String contextName = "executor-channel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*from  w  w w.ja  v a  2  s.c o m*/

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);

    ExecutorChannel channel = applicationContext.getBean("ticketChannel", ExecutorChannel.class);

    channel.subscribe(ticketMessageHandler);

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }
}

From source file:com.newlandframework.test.PojoCallTest.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:rpc-invoke-config-client.xml");

    PersonManage manage = (PersonManage) context.getBean("personManage");

    Person p = new Person();
    p.setId(20150811);/*from  w  w w . jav  a  2 s .  com*/
    p.setName("XiaoHaoBaby");
    p.setAge(1);

    int result = manage.save(p);

    System.out.println("call pojo rpc result:" + result);

    context.destroy();
}

From source file:org.apache.isis.example.wrj.todoitem.ToDoItemSpringClient.java

public static void main(String args[]) throws Exception {
    // Initialize the spring context and fetch our test client
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "classpath:client-applicationContext.xml" });
    ToDoItemTester client = (ToDoItemTester) context.getBean("tester");

    client.testService();/*from   w  w  w.  j  a  v  a2s  . c o m*/
    System.exit(0);
}

From source file:com.alibaba.dubbo.examples.async.AsyncConsumer.java

public static void main(String[] args) throws Exception {
    String config = AsyncConsumer.class.getPackage().getName().replace('.', '/') + "/async-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/*from  w ww .  j a v a2 s.  c  o m*/

    final AsyncService asyncService = (AsyncService) context.getBean("asyncService");

    Future<String> f = RpcContext.getContext().asyncCall(new Callable<String>() {
        public String call() throws Exception {
            return asyncService.sayHello("async call request");
        }
    });

    System.out.println("async call ret :" + f.get());

    RpcContext.getContext().asyncCall(new Runnable() {
        public void run() {
            asyncService.sayHello("oneway call request1");
            asyncService.sayHello("oneway call request2");
        }
    });

    System.in.read();
}

From source file:com.apress.prospringintegration.channels.prioritychannel.Main.java

public static void main(String[] args) {
    String contextName = "priority-channel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*  ww  w.j av  a  2 s.c  o  m*/

    PriorityProblemReporter problemReporter = applicationContext.getBean(PriorityProblemReporter.class);
    PriorityTicketReceiver ticketReceiver = applicationContext.getBean(PriorityTicketReceiver.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }

    Thread consumerThread = new Thread(ticketReceiver);
    consumerThread.start();
}

From source file:com.bt.aloha.batchtest.v2.Main.java

public static void main(String[] args) {
    int res = 256;
    try {//from  ww  w  .  j a v a  2s.com
        String appCtx = "com/bt/aloha/batchtest/v2/RobustnessV2.xml";
        if (args.length != 0)
            appCtx = args[0];
        // load app context
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(appCtx);
        // extracts TestRunner
        TestRunner testRunner = (TestRunner) appContext.getBean("testRunner");
        // runs Test Runner
        ResultTotals resTotal = testRunner.run();
        res = Long.valueOf(resTotal.getFailures()).intValue();
        LOG.info("Results: " + resTotal);
        appContext.destroy();
    } catch (Throwable t) {
        LOG.error("Exception cought in Main", t);
    }
    LOG.info("Returning code: " + res);
    if (res != 0) {
        res = 1;
    }
    // return code is calc module 256
    System.exit(res);
}