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:pkg.AnnotationsMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AnnotationConfig.class);

    Annotations annotation = ctx.getBean(Annotations.class);

    annotation.setMessage("Hello World!");
    annotation.getMessage();/*from  w  w  w  . j a va2  s .  c o m*/
}

From source file:pkg.AnnotationDIMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AnnotationDITextEditorConfig.class);

    AnnotationDITextEditor te = ctx.getBean(AnnotationDITextEditor.class);

    te.spellCheck();/*from  www . j a  v a  2  s  .co  m*/

    /*
    Inside SpellChecker constructor.
    Inside TextEditor constructor.
    Inside checkSpelling.
    */
}

From source file:com.mastermind.shell.Main.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            ApplicationConfig.class);
    Shell shell = context.getBean(Shell.class);

    shell.start();//from   w  w w .  ja v  a  2 s . co  m
}

From source file:x595.Main.java

public static void main(String... args) {
    @SuppressWarnings("resource")
    ApplicationContext ctx = new AnnotationConfigApplicationContext(JpaConfig.class);

    CarRepository repo = ctx.getBean(CarRepository.class);

    log("Start testing CarRepository");

    LicenceInfo info1 = new LicenceInfo("Jane Doe", "jane@corp.com", new Date(), "N17D3E");
    LicenceInfo info2 = new LicenceInfo("Josh Maxwell", "josh@googol.com", new Date(), "G99331");
    LicenceInfo info3 = new LicenceInfo("JD", "saxe@me.com", new Date(), "HL9010");
    LicenceInfo info4 = new LicenceInfo("Triple corp", "triple@doodle.org", new Date(), "JDC13X");
    LicenceInfo info5 = new LicenceInfo("JD", "pro4@k5.com", new Date(), "A75Dc1");

    Car c1 = new Car("AMG", "A4", 2012, 110, info1);
    Car c2 = new Car("Genesis", "G20", 2008, 170, info2);
    Car c3 = new Car("Lena", "sigma", 2015, 150, info3);
    Car c4 = new Car("AMG", "A7", 2010, 130, info4);
    Car c5 = new Car("Tesla", "T1", 2011, 90, info5);

    log("Part 0. insert cars");
    repo.save(c1);/*from   www.j a va  2  s  . c  o  m*/
    repo.save(c2);
    repo.save(c3);
    repo.save(c4);
    repo.save(c5);

    Iterator<Car> it = repo.findAll().iterator();
    log("Part 0. result of inserted car: ");
    while (it.hasNext()) {
        log(it.next().toString());
    }

    log("Part 1. findByOrderByMakerAsc");
    it = repo.findByOrderByMakerAsc().iterator();
    log("Result: ");
    while (it.hasNext()) {
        log(it.next().toString());
    }

    log("Part 2. findByLicenseInfoOwnerName");
    it = repo.findByLicenseInfoOwnerName("JD").iterator();
    log("Result: ");
    while (it.hasNext()) {
        log(it.next().toString());
    }

    log("Part 3. findByMaker");
    it = repo.findByMaker("AMG").iterator();
    log("Result: ");
    while (it.hasNext()) {
        log(it.next().toString());
    }

    log("Part 4. findByMakeYearBetween");
    it = repo.findByMakeYearBetween(2010, 2013).iterator();
    log("Result: ");
    while (it.hasNext()) {
        log(it.next().toString());
    }

    log("Part 5. findByLicenseInfoLicensePlateNumber");
    Car c = repo.findByLicenseInfoLicensePlateNumber("HL9010");
    log("Result: ");
    log(c.toString());

}

From source file:com.as.sagma.ProbarCuentas.java

public static void main(String args[]) {

    ApplicationContext ctx = new AnnotationConfigApplicationContext(ApConfig.class);
    ServicioCuenta cuenta = ctx.getBean(ServicioCuenta.class);
    System.out.println("Bienvenido a la creacion de cuentas");
    // ServicioCuenta cuenta=new CuentaAhorroImpl();
    System.out.println(cuenta.crearCuenta());
}

From source file:com.mycompany.texteditorconfig.MainApp.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(TextEditorConfig.class);

    TextEditor te = ctx.getBean(TextEditor.class);

    te.spellCheck();/*from ww w. java2s. co m*/
}

From source file:com.mycompany.helloworldannotationconfig.MainApp.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(HelloWorldConfig.class);

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

    helloWorld.setMessage("Hello World!");
    helloWorld.getMessage();//from  w  w w  . j  a v  a 2  s .  c o m
}

From source file:com.start.boot.Runner.java

public static void main(String[] args) {

    ctx = new AnnotationConfigApplicationContext(CoreConfigurer.class);

    // now both beans A and B will be available...
    Club a = ctx.getBean(Club.class);
    Person b = ctx.getBean(Person.class);

    System.out.println(a.getName() + a.getId());
    System.out.println(b.getId() + b.getName());
    ctx = null;//from  w w w .ja  va 2  s .c  o m
}

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

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

From source file:com.carranza.web.Probarpersona.java

/**
 * @param args the command line arguments
 *//*from   ww  w  . ja  va  2 s  .  co  m*/
public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(ServiciosChingativos.class);
    Persona p = ctx.getBean(Persona.class);
    p.ejecutarGracia();
    System.out.println(p.ejecutarGracia());
}