Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext close

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext close

Introduction

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

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:ro.lmn.presos.di.emailsender.impl.spring.EmailSenderApp.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EmailSenderApp.class);
    context.getBean(EmailSender.class).sendMail("Hello there", "Buy cheap $product");
    context.close();
}

From source file:pzalejko.iot.hardware.home.core.Main.java

public static void main(String[] args) throws Exception {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            ApplicationConfigurator.class);
    final Application app = context.getBean(Application.class);
    app.start();/*  w  w  w .j  a v  a  2s .  co  m*/
    context.close();
}

From source file:com.mesut.springpropertyinjection.App.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan("com.mesut");
    context.refresh();/*from   w  w  w  .j a  va2  s  . c o m*/

    Person person = context.getBean(Person.class);
    System.out.println("Sonuc: " + person);
    context.close();
}

From source file:com.doctor.ignite.example.spring.SpringIgniteExample2.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            config.class);
    IgniteDao igniteDao = applicationContext.getBean(IgniteDao.class);
    System.out.println("igniteDao:-----------" + igniteDao);
    applicationContext.close();
}

From source file:org.sansdemeure.zenindex.main.Main.java

public static void main(String[] args) {

    Instant start = Instant.now();

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ServiceConfig.class);
    ctx.refresh();//w ww .j a  v  a  2 s  .  c o  m

    BatchService batch = (BatchService) ctx.getBean("batchService");
    batch.start(new File(args[0]));

    ctx.close();

    Instant end = Instant.now();
    logger.info("Duration of batch {}", Duration.between(start, end));

}

From source file:org.dawnsci.marketplace.MarketplaceApplication.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    // convert the command line argument to properties
    CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource(args);
    ctx.getEnvironment().getPropertySources().addFirst(ps);
    ctx.register(ApplicationConfiguration.class);
    ctx.refresh();/*from w w w  .j av a2s .c  o  m*/
    try {
        SpringApplication.run(MarketplaceApplication.class, args);
    } finally {
        ctx.close();
    }
}

From source file:br.com.poc.navigation.NavigationLoader.java

public static void main(String[] args) {

    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            ApplicationContextNavigation.class);

    NavigationLoader navigationLoader = new NavigationLoader();

    navigationLoader.setNavigationComponent(applicationContext.getBean(NavigationComponent.class));

    navigationLoader.startNavigation();//from w ww  . j a va 2  s.c om

    applicationContext.close();

}

From source file:io.gravitee.gateway.platforms.jetty.bootstrap.Bootstrap.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    t.setName("graviteeio-gateway");

    final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(JettyConfiguration.class);
    ctx.registerShutdownHook();//from   www .  j  a v a 2s .  c o  m
    ctx.refresh();

    try {
        final Node node = ctx.getBean(Node.class);
        node.start();

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                LoggerFactory.getLogger(Bootstrap.class).info("Shutting-down Gravitee Gateway...");
                node.stop();
                ctx.close();
            }
        });
    } catch (Exception ex) {
        LOGGER.error("Unable to start Gravitee Gateway", ex);
    }
}

From source file:com.weib.soundsystem.CDPlayerMain.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = null;
    try {//w  w w .j a v a 2  s.  c  o m
        context = new AnnotationConfigApplicationContext(CDPlayerConfig.class);
        //            SgtPeppers sp = (SgtPeppers) context.getBean("sgtPeppers");
        //            sp.play();
        //            CDPlayer cdplayer = context.getBean(CDPlayer.class);
        //            cdplayer.play();

        WhiteAlbum cd = context.getBean(WhiteAlbum.class);
        CDPlayer cdplayer = context.getBean(CDPlayer.class, cd);
        cdplayer.play();

        //            CDPlayer cdwriter = (CDPlayer) context.getBean("cdWriter", (WhiteAlbum)context.getBean("whiteAlbum"));
        //            cdwriter.play();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (context != null) {
            context.close();
        }
    }
}

From source file:com.weib.concert.ConcertMain.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConcertConfig.class);
    //        Director director = context.getBean(Director.class);
    //        director.perform();
    Performance concert = (Performance) context.getBean("concert"); //??Bean Qualifier
    concert.perform();/*from  w w w.jav a  2s  .  c o  m*/

    Performance play = (Performance) context.getBean("play"); //??Bean 
    play.perform();

    /**
     * public class EncoreableIntroducer {
     *       @DeclareParents(value="com.weib.concert.beans.Performance+",   //??
     *               defaultImpl=PerformanceEncoreable.class)            //
     *       public static Encoreable encoreable;
     * }
     */
    Encoreable encoreablePlay = (Encoreable) play; //??(Performance??playproxy??)
    encoreablePlay.performEncore(); //

    context.close();

    AnnotationConfigApplicationContext cdContext = new AnnotationConfigApplicationContext(CDConfig.class);
    CDPlayer cdplayer = cdContext.getBean(CDPlayer.class);
    cdplayer.playAll();
    cdplayer.playShuffle();

    cdContext.close();
}