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.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();/*  w w w .  ja  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();
        }
    }
}

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();//from  w w  w.j  av a2  s .co 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.hikuns.springdata.gemfire.Main.java

/**
 * @param args// w w w .  j  a  v a 2 s . c  o m
 */
public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/gemfire/cache-config.xml");

    @SuppressWarnings("unchecked")
    Region<Object, Object> region = context.getBean("myRegion", Region.class);

    log.debug("populating region ...");
    region.put(1, "apple");
    region.put(2, "banana");
    region.put(3, "pear");

    log.debug("retreiving region values...");

    for (Object obj : region.values()) {
        log.debug(obj);
    }

    log.debug("retreiving region keys...");
    for (Object obj : region.keySet()) {
        log.debug(obj + ":" + region.get(obj));
    }
}

From source file:org.yroffin.neo4b.Bootstrap.java

/**
 * main entry// w ww .j av a2  s . co  m
 * 
 * @param args
 */
public static void main(String[] args) {
    final ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_PATH);
    ((AbstractApplicationContext) context).close();
}

From source file:stsspringframeworkdatagemfire.Main.java

/**
 * @param args/*from w w w .  jav a2s .c  o  m*/
 */
public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/gemfire/cache-config.xml");

    @SuppressWarnings("unchecked")
    Region<Object, Object> region = context.getBean("regionName", Region.class);

    log.debug("populating region ...");
    region.put(1, "apple");
    region.put(2, "banana");
    region.put(3, "pear");

    log.debug("retreiving region values...");

    for (Object obj : region.values()) {
        log.debug(obj);
    }

    log.debug("retreiving region keys...");
    for (Object obj : region.keySet()) {
        log.debug(obj + ":" + region.get(obj));
    }
}

From source file:org.springintegration.NotificationListener.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/spring/integration/remote-monitor-context.xml");
    Gateway gw = ctx.getBean(Gateway.class);
    int cmd = 0;//w w  w.  jav a 2s  .c o  m
    while (cmd != 'q') {
        cmd = System.in.read();
        gw.send((char) cmd);
    }
}

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 ww .  j av  a2 s  .c o  m*/

    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.corespring.i18n.MainI18n.java

public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("ioc_resource_bundles.xml");

    String qMessage = ctx.getMessage("queued", null, Locale.US);
    System.out.println(qMessage);

    qMessage = ctx.getMessage("queued", null, Locale.UK);
    System.out.println(qMessage);

    String filename = "ProSpringIntegration.xml";
    MessageSourceResolvable processed = new DefaultMessageSourceResolvable(new String[] { "complete" },
            new String[] { filename }, " Your data has been processed!");
    String msrQmessage = ctx.getMessage(processed, Locale.FRANCE);
    System.out.println(msrQmessage);

}

From source file:com.dangdang.config.service.easyzk.demo.spring.MainEntrance.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = null;
    try {/*w  w w  .  j  a  va2  s. c om*/
        context = new ClassPathXmlApplicationContext("classpath:config-toolkit-simple.xml");
        context.registerShutdownHook();
        context.start();

        ExampleBeanWithConfigNode bean = context.getBean(ExampleBeanWithConfigNode.class);
        while (true) {
            bean.someMethod();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                //
            }
        }
    } finally {
        if (context != null) {
            context.close();
        }
    }
}

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