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.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  ww  .  ja  v a 2s.  c om
    p.setName("XiaoHaoBaby");
    p.setAge(1);

    int result = manage.save(p);

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

    context.destroy();
}

From source file:com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.SpringNamespaceWithMasterSlaveMain.java

public static void main(final String[] args) throws SQLException {
    // CHECKSTYLE:ON
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/applicationContextWithMasterSlave.xml");
    OrderService orderService = applicationContext.getBean(OrderService.class);
    orderService.insert();/*from  ww  w  .  ja  v a  2 s . c om*/
    orderService.select();
    orderService.delete();
    orderService.select();
}

From source file:com.apress.prospringintegration.claimcheck.ClaimCheckExample.java

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from   w ww .j  a  v  a  2s  . c om

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

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

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*  w  w w  .j  a  va  2s .co m*/

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

From source file:com.ushahidi.swiftriver.core.rules.RulesProcessor.java

@SuppressWarnings("resource")
public static void main(String[] args) {
    AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "applicationContext.xml");

    applicationContext.registerShutdownHook();

}

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. j ava  2 s  . co 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.apress.prospringintegration.transform.ToStringTransformer.java

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

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

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*from   w ww. jav a  2s  .c om*/

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

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

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

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

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*w ww . j  a  v  a  2s  .com*/

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

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

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

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

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*  ww w  .j a v  a 2s.  c om*/

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

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 va 2 s.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();
}