Example usage for org.springframework.context ConfigurableApplicationContext close

List of usage examples for org.springframework.context ConfigurableApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext close.

Prototype

@Override
void close();

Source Link

Document

Close this application context, releasing all resources and locks that the implementation might hold.

Usage

From source file:org.s1p.app3.S1pKafkaApplication.java

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false)
            .run(args);//from  w ww . j a va2s.c o  m
    TestBean testBean = context.getBean(TestBean.class);
    for (int i = 0; i < 10; i++) {
        testBean.send("foo");
    }
    context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS);
    context.close();
}

From source file:org.s1p.app7.S1pKafkaApplication.java

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false)
            .run(args);//from   w w w  . j  av  a 2  s .co m
    TestBean testBean = context.getBean(TestBean.class);
    testBean.send("foo");
    testBean.send("bar");
    testBean.send("baz");
    context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS);
    context.close();
}

From source file:soap.client.Application.java

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    TempConverter converter = ctx.getBean(TempConverter.class);

    GetCreditRate getCreditRate = new GetCreditRate();
    getCreditRate.setArg0(1000.00);/*from w  ww  .  j  av  a2  s .c o m*/
    getCreditRate.setArg1(5);
    getCreditRate.setArg2("a");

    System.out.println("Result: " + converter.fahrenheitToCelcius(getCreditRate));
    ctx.close();
}

From source file:cn.vpclub.spring.boot.kafka.demo2.Application.java

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(Application.class).web(false)
            .run(args);/*from  w w w  .java 2  s  . c  om*/

    KafkaMessageQueue mq = new KafkaMessageQueue(context);
    for (int i = 0; i < 10; i++) {
        String response = mq.receive("demo1.to.demo2", 0);
        if (null != response) {
            mq.send("demo2.to.demo1", null, "test.key", "message replied from demo2", 0);
        }

        logger.info("received: " + response);
        logger.info("sent back to demo1: " + response);

        sleep(100L);
    }

    context.close();
    System.exit(0);
}

From source file:cn.vpclub.spring.boot.kafka.demo3.Application.java

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(Application.class).web(false)
            .run(args);//  ww  w  .  j a  va 2  s .c  o  m

    KafkaMessageQueue mq = new KafkaMessageQueue(context);
    for (int i = 0; i < 10; i++) {
        String response = mq.receive("demo1.to.demo3", 0);
        if (null != response) {
            mq.send("demo3.to.demo1", null, "test.key", "message replied from demo3", 0);
        }

        logger.info("received: " + response);
        logger.info("sent back to demo1: " + response);

        sleep(100L);
    }

    context.close();
    System.exit(0);
}

From source file:com.chevrier.legiondao.boot.Boot.java

public static void main(String[] args) {
    //SpringApplication.run(Boot.class);

    SpringApplication app = new SpringApplication(ConfigJpa.class);
    //app.setLogStartupInfo(false);
    // on la lance
    ConfigurableApplicationContext context = app.run(args);

    PersonnageRepository personnageRepository = context.getBean(PersonnageRepository.class);

    Iterable<Personnage> allPersonnage = personnageRepository.findAll();

    allPersonnage.forEach(perso -> log.info(perso.getNom()));
    System.out.println("Let's inspect the beans provided by Spring Boot:");

    String[] beanNames = context.getBeanDefinitionNames();
    Arrays.sort(beanNames);//from   ww w .j  av  a2  s .com
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }
    // fermeture du contexte Spring
    context.close();
}

From source file:ua.epam.rd.pizzadelivery.SpringPizzaApp.java

public static void main(String[] args) {
    ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext("appContext.xml");

    PizzaRepository pizzaRepository = (PizzaRepository) appContext.getBean("pizzaRepository");
    System.out.println(pizzaRepository);

    String[] beans = appContext.getBeanDefinitionNames();
    for (String b : beans) {
        System.out.println(b);//  w w w.j  a va 2  s . c  om
    }

    Customer customer = new Customer(1, "Andrii");
    OrderService orderService = (OrderService) appContext.getBean("orderService");

    Order order = orderService.placeNewOrder(customer, 1);

    System.out.println(order);

    appContext.close();
}

From source file:com.geas.blog.blog.App.java

License:asdf

public static void main(String[] args) {

    System.out.println("load context");
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    Post testPost = new Post();
    testPost.setPostId(1);//from   w  w w.ja v  a 2s . c om
    testPost.setTitle("John");
    testPost.setBody("l;asdfja;lsdkfj;ladsfj;l;ldkskfja;sldfkja;lsdfjaf;lfdjkas;dlfja;ldsfkja;dlfk");
    PostDBService testPostService = (PostDBService) context.getBean("postService");
    testPostService.persistPost(testPost);
    System.out.println("Updated title :" + testPostService.findPostById(1).getTitle());
    testPost.setTitle("Hello");
    testPostService.updatePost(testPost);
    System.out.println("Updated title :" + testPostService.findPostById(1).getTitle());
    testPostService.deletePost(testPost);
    context.close();
}

From source file:org.fcrepo.upgrade.utils.TechnicalMetadataMigrator.java

/**
 * Migrate technical metadata.//from  w ww  .  j  a va  2  s .  com
 * @param args If "dryrun" is passed as an argument, the utility will print out what would be done,
 *             but no changes will be made.
**/
public static void main(final String[] args) {
    ConfigurableApplicationContext ctx = null;
    try {
        final boolean dryrun;
        if (args.length > 0 && "dryrun".equals(args[0])) {
            dryrun = true;
        } else {
            dryrun = false;
        }

        final TechnicalMetadataMigrator migrator = new TechnicalMetadataMigrator();
        ctx = new ClassPathXmlApplicationContext("classpath:/spring/master.xml");
        ctx.getBeanFactory().autowireBeanProperties(migrator, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE,
                false);
        migrator.run(dryrun);

    } catch (RepositoryException ex) {
        ex.printStackTrace();
    } finally {
        if (null != ctx) {
            ctx.close();
        }
    }
}

From source file:mk.finki.ranggo.aggregator.Aggregator.java

public static void main(String[] args) {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:spring/application-config.xml");

    //make sure alchemyapi.key hold your license key
    final String alchemyapi_key = context.getBeanFactory().resolveEmbeddedValue("${alchemyapi.key}");

    PersonRepository personRepository = context.getBean(PersonRepository.class);
    ContentRepository contentRepository = context.getBean(ContentRepository.class);

    ContentsAggregator aggregator = new ContentsAggregatorImpl(alchemyapi_key, personRepository,
            contentRepository);/*www. ja va 2s.com*/

    //populates the data store with the test dataset
    Aggregator.test(aggregator);

    //executes update method
    Aggregator.update(null, aggregator);

    context.close();
}