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

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

Introduction

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

Prototype

public AnnotationConfigApplicationContext(String... basePackages) 

Source Link

Document

Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.

Usage

From source file:jms001.EntryPoint.java

public static void main(String... args) {
    System.out.println("Hello world");
    applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
}

From source file:gordonchild.springfx.Application.java

public static void main(String[] args) throws Throwable {
    //SpringApplication.run(Application.class, args);
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
}

From source file:com.example.spring.app.JavaConfig.java

public static void main(String[] args) {

    ApplicationContext ctx = new AnnotationConfigApplicationContext(HelloWorldConfig.class);

    HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

    helloWorld.setMessage("Hello World!");
    System.out.println("########## Message ######### " + helloWorld.getMessage());

    TextEditor te = ctx.getBean(TextEditor.class);
    te.spellCheck();/*from ww w. ja  v  a 2 s.c  o  m*/
}

From source file:org.adamkrajcik.winecellars.Main.java

public static void main(String[] args) {

    log.info("zaciname");
    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
    CellarManager cellarManager = ctx.getBean("cellarManager", CellarManager.class);

    List<Cellar> allCellars = cellarManager.findAllCellars();
    System.out.println("all Cellars = " + allCellars);

}

From source file:co.id.ipb.ilkom.training.db.CustomerServiceJpaExample.java

public static void main(String[] args) {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringDataJpaConfiguration.class);
    CustomerService customerService = applicationContext.getBean(CustomerService.class);
    Customer customer = new Customer();
    customer.setId(10);/*  ww  w .j  a v  a 2 s.  com*/
    customer.setName("Fulan");
    customer.setEmail("fulan@email.com");
    customer.setAddress("kampus IPB");
    customer.setBirthDate(new Date());
    customerService.saveOrUpdate(customer);
}

From source file:com.spring.tutorial.configuration.beansconfig.javaconfig.App.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
    Foo foo = ctx.getBean(Foo.class);
    ((AnnotationConfigApplicationContext) ctx).close();
}

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

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = null;
    try {/* www  . j  ava 2 s.  co 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   ww  w.ja v 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();
}

From source file:com.home.ln_spring.ch5.javaconfig.JavaConfigSimpleExample.java

public static void main(String[] args) {
    ApplicationContext context =//from w  ww.  j  a va 2  s .c o  m
            //new ClassPathXmlApplicationContext("classpath:app-context.xml");
            new AnnotationConfigApplicationContext(AppConfig.class);

    MessageRenderer renderer = context.getBean("messageRenderer", MessageRenderer.class);

    renderer.render();
}

From source file:com.mycompany.spring.context.demo.Application.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
    MessagePrinter printer = context.getBean(MessagePrinter.class);
    printer.printMessage();/*from   w  w  w. j a v  a2 s .  c  o m*/
}