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:sg.edu.ntu.hrms.test.SpringTest.java

/**
 * @param args the command line arguments
 *///from w w  w  .  j a  v a2s.  c  om
public static void main(String[] args) {
    // TODO code application logic here
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
    //appContext.register(AppConfig.class);

    LoginService login = (LoginService) ctx.getBean(LoginService.class);
    UserDTO auth = login.authenticate("derique", "pass");
    if (auth != null) {
        System.out.println("auth success");
    } else {
        System.out.println("auth failed");
    }
}

From source file:prospring3.ch5.beanpostprocessor.DeassociateMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Ch5Config.class);
    final FacebookService facebookService = ctx.getBean(FacebookService.class);
    facebookService.deassociate();/*from   w  w w  . j  ava2s . co m*/
    System.out.println("Finish");
}

From source file:br.com.joaops.springdatajpajavaconfigfirebird.Main.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            DataConfiguration.class)) {
        BookService service = context.getBean(BookService.class);
        Book book = new Book("First Book", new Date(), 33, new BigDecimal(26.50));
        service.save(book);/*from w ww  .  j a va 2 s.c o  m*/
        List<Book> books = service.findAll();
        for (Book b : books) {
            System.out.println(b);
        }
    }
}

From source file:de.htw_berlin.f4.ai.kbe.kurznachrichten.app.App.java

public static void main(String[] args) {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    ShortMessageService sms = (ShortMessageService) context.getBean("ShortMessageService");

    sms.createUser("hans", "leibzisch");
    System.out.println("User hans created");
    //        sms.createUser("peter", "dresdn");
    sms.createTopic("hans", "pegida");
    long id = sms.createMessage("hans", "testnachricht am Ursprung", "pegida");
    long respID = sms.respondToMessage("hans", "rumstehn tut der da glaube ich", id);
    //        System.out.println(sms.getUsers());
    //        System.out.println(sms.getTopics());
    System.out.println("Message by Topic Pegida:");

    System.out.println("\t" + sms.getMessageByTopic("pegida", null).get(0).get(0).getContent());

    try {//from w w w .  j  av  a  2 s  .com
        System.out.println("Delete message");
        sms.deleteMessage("hans", id);
    } catch (AuthorizationException e) {
        e.printStackTrace();
    }
    //        EntityManager em = EntityManagerFactory.getInstance().getEntitymanager();
    //
    //        createMessage(em);
    //        printAllMessages(em);

}

From source file:SpringInAction4Edition.MainApp.java

public static void main(String[] args) {

    ApplicationContext context = new AnnotationConfigApplicationContext(CDConfig.class);

    Environment env = context.getEnvironment();
    System.err.println("environment : ime : " + env.getProperty("ime"));
    System.err.println("environment : prezime : " + env.getProperty("prezime"));

    KutijaCD cd_ovi = context.getBean(KutijaCD.class);
    CDPlayer cDPlayer = context.getBean(CDPlayer.class);

    cd_ovi.getCds().stream().forEach((cd) -> {
        cd.play();//w  w  w . ja  v a2 s  .  co m
    });

    cDPlayer.getCd();
    System.err.println("BEAN DEF NAMES : " + Arrays.toString(context.getBeanDefinitionNames()));
}

From source file:com.apress.prospringintegration.corespring.spel.MainSpEL.java

public static void main(String[] ars) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpELConfig.class);

    EmailUtilities emailUtils = ctx.getBean(EmailUtilities.class);
    System.out.println(emailUtils.getHost());
}

From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainRmiService.java

public static void main(String[] args) {
    new AnnotationConfigApplicationContext(RmiServiceConfig.class);
}

From source file:com.apress.prospringintegration.concurrency.taskexecutorexample.TaskExecutorExampleApp.java

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(TaskExecutorExampleConfiguration.class);
    TaskExecutorExample demo = ctx.getBean(TaskExecutorExample.class);
    demo.submitJobs();//ww w  . j a  v a 2 s  .c  om
}

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();/*  ww  w .j a va 2s.c o m*/
    context.close();
}

From source file:com.facio.Main.java

public static void main(String[] args) {
    LOG.info("start main and loading application context...");
    int i = 0;//from w w w .  ja  v a2 s . c  o m
    String[] names = { "Vai Planeta", "Fabiano", "Lucas" };

    ApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);

    HeavyService bean = ctx.getBean(HeavyService.class);
    IDummyComponent<String, String> dummy = ctx.getBean(IDummyComponent.class);

    //        for (i = 0; i < 3; i++) {
    //            LOG.info("calling hello... for the [" + i + "] time");
    //            String hello = bean.hello(names[0]);
    //            LOG.debug("Say.:" + hello);
    //            LOG.info("hello called.");
    //        }

    dummy.getValue("mykey", "myname");
}