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:poc.telnet.TelnetServer.java

public static void main(String[] args) throws Exception {
    new ClassPathXmlApplicationContext("/META-INF/spring/integration/telnet-inbound.xml");
    System.out.println("Press Enter/Return in the console to exit");
    System.in.read();/*w w w  . j av a 2 s  .  co  m*/
    System.exit(0);
}

From source file:com.alibaba.dubbo.examples.redis.RedisConsumer.java

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

From source file:com.alibaba.dubbo.examples.version.VersionConsumer.java

public static void main(String[] args) throws Exception {
    String config = VersionConsumer.class.getPackage().getName().replace('.', '/') + "/version-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/*from ww w .java2 s  . co m*/
    VersionService versionService = (VersionService) context.getBean("versionService");
    for (int i = 0; i < 10000; i++) {
        String hello = versionService.sayHello("world");
        System.out.println(hello);
        Thread.sleep(2000);
    }
    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();/*from   w  w  w .ja v  a 2s.  co 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.apress.prospringintegration.channels.queuechannel.TicketMain.java

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

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//from  w w w.ja va2 s .  c  o  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:occi.libvirt.StartClass.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("resources/conf/beans.xml");
    BeanFactory factory = context;//from w  w  w. j a  va  2 s  .c  o m
    Injection test = (Injection) factory.getBean("Injection");
    try {
        occiApi.main(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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  w w.ja v  a  2 s . c o m

    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:org.ogcs.okra.example.game.Bootstrap.java

public static void main(String[] args) {
    LOG.info("PreBootstrap server.");
    ClassPathXmlApplicationContext context = null;
    try {/*w ww  .j a  v a2  s .c  o m*/
        context = new ClassPathXmlApplicationContext("classpath:spring/beans.xml");
        context.registerShutdownHook();
        LOG.info("Server bootstrap successful.");
    } catch (Exception e) {
        if (context != null)
            context.close();
        LOG.error("Server bootstrap failure.", e);
    }
}

From source file:com.hazelcast.hibernate.app.Main.java

public static void main(String[] args) throws Exception {
    LogManager.getLogManager().reset();
    SLF4JBridgeHandler.install();/*from   w  w w. jav  a  2  s  . com*/

    ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("/app-context.xml");
    Executor executor = applicationContext.getBean(Executor.class);

    // Start and wait for finishing work
    executor.execute();

    applicationContext.close();
}

From source file:com.apress.prospringintegration.social.feed.FeedInboundApp.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("/spring/feed/feed-inbound.xml");

    PollableChannel feedChannel = context.getBean("feedChannel", PollableChannel.class);

    for (int i = 0; i < 10; i++) {
        Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
        if (message != null) {
            SyndEntry entry = message.getPayload();
            System.out.println(entry.getPublishedDate() + " - " + entry.getTitle());
        } else {/*from   ww  w. ja va2 s .  c o  m*/
            break;
        }
    }
}