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:com.apress.prospringintegration.springenterprise.stocks.runner.MainHibernate.java

public static void main(String[] args) {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(
            "com.apress.prospringintegration.springenterprise.stocks.dao.hibernate");

    StockDao stockDao = context.getBean("hibernateStockDao", StockDao.class);
    Stock stock = new Stock("ORAC", "HIBERNATEMAIN0001", "QQQQ", 120.0f, 1100,
            Calendar.getInstance().getTime());
    stockDao.insert(stock);/*from   w  ww.  j a  v a 2 s .co  m*/

    stock = stockDao.findByInventoryCode("HIBERNATEMAIN0001");

    if (stock != null) {
        System.out.println("Stock Symbol :" + stock.getSymbol());
        System.out.println("Inventory Code :" + stock.getInventoryCode());
        System.out.println("purchased price:" + stock.getSharePrice());
        System.out.println("Exchange ID:" + stock.getExchangeId());
        System.out.println("Quantity Available :" + stock.getQuantityAvailable());
    }
}

From source file:lab.home.spring.redis.test.SpringRedisTest.java

public static void main(String argv[]) {

    ApplicationContext ctx = new AnnotationConfigApplicationContext(RedisTestConfig.class);
    DictionaryDao ddao = ctx.getBean(DictionaryDao.class);

    try {/*from  w  w w  . ja  va 2s  . c  o  m*/
        System.out.println("ddao.setValue(\"key1\", \"value1\")");
        ddao.setValue("key1", "value1");
        System.out.println("ddao.setValue(\"testkey\", \"testvalue\")");
        ddao.setValue("testkey", "testvalue");
        System.out.println("getting value for key1 = " + ddao.getValue("key1"));
        System.out.println("getting value for testkey = " + ddao.getValue("testkey"));
    } catch (Exception e) {
        System.out.println(e);
        System.out.println(e.fillInStackTrace());
        System.out.println(e.getCause());
        System.out.println(e.getClass());
        System.out.println(e.getStackTrace());
        e.printStackTrace();
    }
}

From source file:com.jc.campitos.Testito.java

public static void main(String args[]) {
    System.out.println("Bienvenido al maravilloso mundo de SPRING");
    /* FileSystemXmlApplicationContext ctx=
          new FileSystemXmlApplicationContext("web/WEB-INF/dispatcher-servlet.xml");
             //from  w ww.j  a  v  a 2s . c o  m
              
      ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("lugar de xml dentro de"
           + "los paquetes de clases");
              
      */

    /*   Cargamos en contexto solo con codigo java   */
    ApplicationContext ctx = new AnnotationConfigApplicationContext(ApConfig.class);
    ServicioCuenta cuenta = ctx.getBean(ServicioCuenta.class);
    System.out.println(cuenta.crearCuenta());

    //Otro ejemplo ms pero con una nomina... este es otro ejemplo de servicio trasnversal
    ServicioNomina nomina = ctx.getBean(ServicioNomina.class);
    System.out.println(nomina.pagarNomina());

}

From source file:com.khartec.waltz.jobs.AccessLogHarness.java

public static void main(String[] args) throws ParseException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    AccessLogDao accessLogDao = ctx.getBean(AccessLogDao.class);

    accessLogDao.write(ImmutableAccessLog.builder().params("{b:2}").state("my.state").userId("bob").build());

    accessLogDao.findForUserId("bob").forEach(System.out::println);

}

From source file:com.khartec.waltz.jobs.UserAgentInfoHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    UserAgentInfoDao userLoginDao = ctx.getBean(UserAgentInfoDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<UserAgentInfo> infos = userLoginDao.findLoginsForUser("admin", 10);
    System.out.println(infos);//w  w w  . j a  va 2  s. co m

    userLoginDao.save(infos.get(0));
}

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

public static void main(String[] args) {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(
            "com.apress.prospringintegration.springenterprise.stocks.dao.jpa");

    StockDao stockDao = context.getBean("jpaStockDao", StockDao.class);
    Stock stock = new Stock("ORAC", "JPAMAIN0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime());
    stockDao.insert(stock);//from   w  w  w.  ja  v a2s . co m

    List<Stock> stocks = stockDao.findAvailableStockBySymbol("ORAC");

    if (stocks != null && stocks.size() > 0) {
        stock = stocks.get(0);
        System.out.println("Stock Symbol :" + stock.getSymbol());
        System.out.println("Inventory Code :" + stock.getInventoryCode());
        System.out.println("purchased price:" + stock.getSharePrice());
        System.out.println("Exchange ID:" + stock.getExchangeId());
        System.out.println("Quantity Available :" + stock.getQuantityAvailable());
    }
}

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

public static void main(String[] args) {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(
            "com.apress.prospringintegration.springenterprise.stocks.client");

    QuoteServiceClient client = context.getBean("client", QuoteServiceClient.class);

    List<Quote> myQuotes = new ArrayList<Quote>();
    myQuotes.add(client.getMyQuote("APRESS"));
    myQuotes.add(client.getMyQuote("SPRNG"));
    myQuotes.add(client.getMyQuote("INTGRN"));

    for (Quote myQuote : myQuotes) {
        System.out.println("Symbol : " + myQuote.getSymbol());
        System.out.println("Price  :" + myQuote.getPrice());
        System.out.println("Exchange: " + myQuote.getExchangeId());
    }/* w w  w.  jav  a  2  s .c  o m*/
}

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

public static void main(String[] args) {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(
            "com.apress.prospringintegration.springenterprise.stocks.dao.jpaandentitymanagers");

    StockDao stockDao = context.getBean("jpaStockDao", StockDao.class);
    Stock stock = new Stock("ORAC", "JPAMAIN0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime());
    stockDao.insert(stock);//from   w  w w .ja v  a2s .  c  o m

    List<Stock> stocks = stockDao.findAvailableStockBySymbol("ORAC");

    if (stocks != null && stocks.size() > 0) {
        stock = stocks.get(0);
        System.out.println("Stock Symbol :" + stock.getSymbol());
        System.out.println("Inventory Code :" + stock.getInventoryCode());
        System.out.println("purchased price:" + stock.getSharePrice());
        System.out.println("Exchange ID:" + stock.getExchangeId());
        System.out.println("Quantity Available :" + stock.getQuantityAvailable());
    }
}

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 w  ww .j av  a 2  s. com*/
}

From source file:com.stratio.streaming.StreamingEngine.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            BaseConfiguration.class)) {

        annotationConfigApplicationContext.registerShutdownHook();

        Map<String, JavaStreamingContext> contexts = annotationConfigApplicationContext
                .getBeansOfType(JavaStreamingContext.class);

        for (JavaStreamingContext context : contexts.values()) {
            context.start();/*from www.  j a  v a2 s.c  o m*/
            log.info("Started context {}", context.sparkContext().appName());
        }
        contexts.get("actionContext").awaitTermination();
    } catch (Exception e) {
        log.error("Fatal error", e);
    }
}