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[] paths, Class<?> clazz) 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:org.springone2gx_2011.integration.loadbalancing.LbFailoverDemo.java

public static void main(String[] args) {
    ActiveMqTestUtils.prepare();/*www.  j a  v  a 2  s . c o m*/
    ApplicationContext context = new ClassPathXmlApplicationContext("lb-config.xml", LbFailoverDemo.class);
    MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
    inputChannel.send(new GenericMessage<String>("A"));
    inputChannel.send(new GenericMessage<String>("B"));
    inputChannel.send(new GenericMessage<String>("C"));
}

From source file:com.springsource.samples.resttemplate.Driver.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java " + Driver.class.getName() + " [Flickr API key] [search term]");
        System.exit(-1);//from w w w.j a  v  a 2s .  com
    }
    String apiKey = args[0];
    String searchTerm = args[1];

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml",
            Driver.class);
    FlickrClient client = (FlickrClient) applicationContext.getBean("flickrClient", FlickrClient.class);
    client.doIt(apiKey, searchTerm);
}

From source file:com.oreilly.springdata.hadoop.hive.HiveApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hive-context.xml",
            HiveApp.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();//from   w ww . j av  a 2  s  . c o m

    HiveTemplate template = context.getBean(HiveTemplate.class);
    log.info(template.query("show tables;"));

    PasswordRepository repository = context.getBean(HiveTemplatePasswordRepository.class);
    repository.processPasswordFile("/etc/passwd");
    log.info("Count of password entries = " + repository.count());

}

From source file:com.springdeveloper.hadoop.hive.HiveJdbcApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/hive-jdbc-context.xml", HiveJdbcApp.class);
    log.info("Hive JDBC Application Running");
    context.registerShutdownHook();//w  ww .  ja v a 2  s.c om

    String tableDdl = "create external table if not exists tweetdata (value STRING) LOCATION '/tweets/input'";
    String query = "select r.retweetedUser, '\t', count(r.retweetedUser) as count " + " from tweetdata j "
            + " lateral view json_tuple(j.value, 'retweet', 'retweetedStatus') t as retweet, retweetedStatus "
            + " lateral view json_tuple(t.retweetedStatus, 'fromUser') r as retweetedUser "
            + " where t.retweet = 'true' " + " group by r.retweetedUser order by count desc limit 10";
    String results = "insert overwrite directory '/tweets/hiveout'";

    JdbcTemplate template = context.getBean(JdbcTemplate.class);
    template.execute(tableDdl);

    template.execute(results + " " + query);

    context.close();
}

From source file:siia.monitoring.controlbus.ControlBusDemo.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("context.xml", ControlBusDemo.class);
    NumberHolder numberHolder = context.getBean("numberHolder", NumberHolder.class);
    MessageChannel controlChannel = context.getBean("controlChannel", MessageChannel.class);
    System.out.println("number before increment: " + numberHolder.getNumber());
    Message<String> message = MessageBuilder.withPayload("@numberHolder.increment()").build();
    controlChannel.send(message);/*  w ww  .  j a v a2  s . c  o m*/
    System.out.println("number after increment:  " + numberHolder.getNumber());
    FilePoller filePoller = context.getBean("filePoller", FilePoller.class);
    System.out.println("file poller isRunning before start: " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("@filePoller.start()").build());
    System.out.println("file poller isRunning after start:  " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("@filePoller.stop()").build());
    System.out.println("file poller isRunning after stop:   " + filePoller.isRunning());
    ThreadPoolTaskExecutor executor = context.getBean("myExecutor", ThreadPoolTaskExecutor.class);
    System.out.println("max pool size before update: " + executor.getMaxPoolSize());
    controlChannel.send(MessageBuilder.withPayload("@myExecutor.setMaxPoolSize(25)").build());
    System.out.println("max pool size after update:  " + executor.getMaxPoolSize());
}

From source file:siia.monitoring.controlbus.GroovyControlBusDemo.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("groovy-context.xml",
            GroovyControlBusDemo.class);
    NumberHolder numberHolder = context.getBean("numberHolder", NumberHolder.class);
    MessageChannel controlChannel = context.getBean("controlChannel", MessageChannel.class);
    System.out.println("number before increment: " + numberHolder.getNumber());
    Message<String> message = MessageBuilder.withPayload("numberHolder.increment()").build();
    controlChannel.send(message);//from w ww.  ja v  a 2 s  .  co m
    System.out.println("number after increment:  " + numberHolder.getNumber());
    FilePoller filePoller = context.getBean("filePoller", FilePoller.class);
    System.out.println("file poller isRunning before start: " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("filePoller.start()").build());
    System.out.println("file poller isRunning after start:  " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("filePoller.stop()").build());
    System.out.println("file poller isRunning after stop:   " + filePoller.isRunning());
    ThreadPoolTaskExecutor executor = context.getBean("myExecutor", ThreadPoolTaskExecutor.class);
    System.out.println("max pool size before update: " + executor.getMaxPoolSize());
    controlChannel.send(MessageBuilder.withPayload("myExecutor.setMaxPoolSize(25)").build());
    System.out.println("max pool size after update:  " + executor.getMaxPoolSize());
}

From source file:org.apache.mina.springrpc.example.gettingstarted.config.SpringHelloServiceExporter.java

public static void main(String[] args) {
    StopWatch sw = new StopWatch("HelloServiceExporter");
    sw.start();// w  ww  . j a va  2 s . c  om
    new ClassPathXmlApplicationContext("hello-service-exporter.xml", SpringHelloServiceExporter.class);
    sw.stop();
    logger.info(sw.prettyPrint());
}

From source file:com.oreilly.springdata.hadoop.pig.PigAppWithRepository.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/pig-context-password-repository.xml", PigAppWithRepository.class);
    log.info("Pig Application Running");
    context.registerShutdownHook();/*from w w  w.ja  va  2 s.c  om*/

    String outputDir = "/data/password-repo/output";
    FsShell fsShell = context.getBean(FsShell.class);
    if (fsShell.test(outputDir)) {
        fsShell.rmr(outputDir);
    }

    PasswordRepository repo = context.getBean(PigPasswordRepository.class);
    repo.processPasswordFile("/data/passwd/input");

    /*
    Collection<String> files = new ArrayList<String>();
    files.add("/data/passwd/input");
    files.add("/data/passwd/input2");
    repo.processPasswordFiles(files);
    */

}

From source file:koper.demo.main.SendDataEventMsgDemo.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml",
            "kafka/context-data-producer.xml");

    Order order = new Order();
    order.setId(100);/*from w  w  w.j av  a2s  .  co m*/
    order.setOrderNo("order_no");
    order.setCreatedTime("oroder_created_time");

    OrderService orderService = (OrderService) context.getBean("orderServiceImpl");
    orderService.insertOrder(order);
    orderService.updateOrder(order);
}

From source file:org.springone2gx_2011.integration.aggregator.AggregatorDemo.java

/**
 * @param args/* w  w  w  .  j ava 2  s  . c  om*/
 */
public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("aggregator-config.xml",
            AggregatorDemo.class);
    MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
    int iterations = 13;
    for (int i = 0; i < iterations; i++) {
        Message<?> message = MessageBuilder.withPayload(i).setCorrelationId(1).setSequenceNumber(i)
                .setSequenceSize(iterations).build();
        System.out.println("Sending: " + message);
        inputChannel.send(message);

        Thread.sleep(1000);
    }
}