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

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

Introduction

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

Prototype

public ClassPathXmlApplicationContext(String... configLocations) throws BeansException 

Source Link

Document

Create a new ClassPathXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Usage

From source file:com.apress.prospringintegration.transform.MapTransformer.java

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

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);//from  w w w .  jav  a2 s .co  m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.XmlTransformer.java

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

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);// www  . ja va 2s . c o m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:org.apache.cxf.transport.xmpp.pep.Client.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("client-pep-applicationContext.xml");
    HelloWorld client = (HelloWorld) context.getBean("helloClient");

    long startTime = System.currentTimeMillis();
    client.yell("One way message!!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    startTime = System.currentTimeMillis();
    client.yell("Second message!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
}

From source file:org.mshariq.cxf.brave.Server.java

public static void main(String args[]) throws Exception {
    ApplicationContext appctxt = new ClassPathXmlApplicationContext(
            Server.class.getResource("/context.xml").toString());

    System.out.println("Server ready...");

    Thread.sleep(5 * 6000 * 1000);
    System.out.println("Server exiting");
    System.exit(0);/*from  w  w  w .j  av  a 2  s.co m*/
}

From source file:com.apress.prospringintegration.transform.JsonTransformer.java

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

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);//w w  w.  j  a  v a 2s  .c o m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:org.apache.cxf.transport.xmpp.pubsub.Client.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("client-pubsub-applicationContext.xml");
    HelloWorld client = (HelloWorld) context.getBean("helloClient");

    long startTime = System.currentTimeMillis();
    client.yell("One way message!!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    startTime = System.currentTimeMillis();
    client.yell("Second message!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
}

From source file:com.apress.prospringintegration.corespring.config.componentscan.javaconfig.MainJavaConfig.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("ioc_java_config.xml");
    ColorRandomizer cr = context.getBean("theOnlyColorRandomizer", ColorRandomizer.class);
    System.out.println(cr.randomColor());

    for (int i = 0; i < 5; i++)
        System.out.println("randomcolor: " + context.getBean("randomColor", ColorEnum.class));
}

From source file:org.apache.cxf.transport.xmpp.iq.Client.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("client-iq-applicationContext.xml");
    HelloWorld client = (HelloWorld) context.getBean("helloClient");

    long startTime = System.currentTimeMillis();
    String serviceResponse = client.sayHi("XMPP Service Call-1");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
    System.out.println("Service said: " + serviceResponse);

    startTime = System.currentTimeMillis();
    serviceResponse = client.sayHi("XMPP Service Call-2");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
    System.out.println("Service said: " + serviceResponse);

}

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

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

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

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

    Queue queue = applicationContext.getBean(Queue.class);

    admin.declareQueue(queue);

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

        Thread.sleep(5000);
    }
}

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();/* w  w w .j  a v a 2 s  .c o  m*/
    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();
        }
    }
}