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.bow.rest.RestConsumer.java

public static void main(String[] args) throws Exception {
    String config = RestConsumer.class.getPackage().getName().replace('.', '/') + "/rest-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//  w w w.  j  a v a  2s  . c  o  m
    AnotherUserRestService userService = (AnotherUserRestService) context.getBean("anotherUserRestService");

    User user = new User(1L, "larrypage");
    System.out.println("SUCCESS: registered user with id " + userService.registerUser(user).getId());

    RpcContext.getContext().setAttachment("clientName", "demo");
    RpcContext.getContext().setAttachment("clientImpl", "dubbox");
    System.out.println("SUCCESS: got user " + userService.getUser(1L));
    System.in.read();
}

From source file:org.opencredo.cloud.storage.samples.quote.S3QuoteDemo.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("quoteDemo-context.xml");

    TickerUploader tickerUploader = (TickerUploader) context.getBean("tickerUploader");
    // sending requests for tickers to be uploaded to S3, so that they can
    // later be read by another application.
    // can be commented out if already uploaded enough information
    for (int i = 0; i < 4; i++) {
        char[] chars = new char[3];
        for (int j = 0; j < 3; j++) {
            chars[j] = (char) (new Random().nextInt(25) + 65);
        }/*  w  w  w .j av a  2  s .  c om*/
        String ticker = new String(chars);
        LOG.info("ticker to upload: {}", ticker);
        MessageBuilder<String> builder = MessageBuilder.withPayload(ticker);
        tickerUploader.sendTicker(builder.build());
    }
}

From source file:com.alibaba.dubbo.examples.memcached.MemcachedConsumer.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String config = MemcachedConsumer.class.getPackage().getName().replace('.', '/')
            + "/memcached-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();//from ww  w  .  ja  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");
    }
    System.in.read();
}

From source file:com.apress.prospringintegration.messaging.activemq.jms.adapter.TicketReporterMain.java

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*  w w w  .ja  v a 2  s  .  com*/

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

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

        Thread.sleep(5000);
    }
}

From source file:com.apress.prospringintegration.serviceactivator.Main.java

public static void main(String[] args) throws Exception {
    String contextName = "service-activator.xml";

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

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

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

        Thread.sleep(500);
    }
}

From source file:camel.Main.java

public static void main(String args[]) throws Exception {
    new ClassPathXmlApplicationContext("broker.xml", Main.class);
    new ClassPathXmlApplicationContext("consumer.xml", Main.class);
    ClassPathXmlApplicationContext producer = new ClassPathXmlApplicationContext("producer-temp-reply.xml",
            Main.class);
    CamelContext producerContext = producer.getBean(CamelContext.class);

    ProducerTemplate producerTemplate = producerContext.createProducerTemplate();

    producerTemplate.setDefaultEndpointUri("direct:invokeCamelOutQueue");
    System.out.println("\n=== Started Camel Request/Reply performance test with Temporary Reply Queue ===\n");
    for (int i = 0; i < 50; i++) {
        testBatchOfMessages(producerTemplate, 20000, i);
    }//from  w w  w  .  j av  a 2  s .c  om
    System.out.println("******* The END *******");
}

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

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*from  w ww. j  a va 2 s.com*/

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketReceiver ticketReceiver = applicationContext.getBean(TicketReceiver.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.apress.prospringintegration.channels.queuechannel.EmergencyTicketMain.java

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//from w  w w.java2s  .  com

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    EmergencyTicketReceiver ticketReceiver = applicationContext.getBean(EmergencyTicketReceiver.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.apress.prospringintegration.channels.queuechannel.TicketMain.java

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/* w w  w  .  j  a  v  a 2s .co m*/

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketReceiver ticketReceiver = applicationContext.getBean("ticketReceiver", TicketReceiver.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.insonix.cxf.client.PersonServiceClient.java

@SuppressWarnings("resource")
public static void main(String args[]) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "cxf-servlet.xml" });

    PersonService personService = (PersonService) context.getBean("personClient");

    Person person = personService.getPerson(1);
    System.out.println("Response: " + person.getName());
    System.exit(0);//from w  w w .j  a  v a 2 s.  c  o  m
}