Example usage for org.springframework.context ApplicationContext getBean

List of usage examples for org.springframework.context ApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBean.

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:com.netpet.spools.spring.springtest.testQuickStart.java

/**
 * The special way (DI in Spring) for reading from config file.
 * @param args//w  w  w. j  ava 2s .  co m
 * Testing by Using Spring!
 */
public static void main(String[] args) {
    ApplicationContext ctx = new FileSystemXmlApplicationContext("springTest/bean.xml");
    Action action = (Action) ctx.getBean("theAction");
    Action secondAction = (Action) ctx.getBean("secondAction");

    int i = 0;
    System.out.println(action.execute("Trigger Jonathan:") + i++);
    System.out.println(secondAction.execute("bootstrap:") + i++);

    for (i = 0; i < 10; i++) {
        if (i == 6) {
            continue;
        }
        System.out.println(i);
    }
}

From source file:com.alibaba.akka.AkkaMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("biz-actor.xml");

    DataQueryService dataQueryService = (DataQueryService) ctx.getBean("dataQueryService");
    QueryParam queryParam = new QueryParam();
    List<Item> items = dataQueryService.query(queryParam);
    for (Item item : items) {
        System.out.println(item.getContent());
    }/*from w ww.  j  a  va 2s  .c  o  m*/
}

From source file:com.tservice.Facade.Main.java

/**
 * @param args the command line arguments
 *//*from   w  ww.j a v a  2s .co  m*/
public static void main(String[] args) {

    // TODO code application logic here
    ApplicationContext ap = new ClassPathXmlApplicationContext("/applicationContext.xml");
    PersistenceFacede l = (PersistenceFacede) ap.getBean(PersistenceFacede.class);

}

From source file:pkg.BeanMain.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

    BeanInheritance objA = (BeanInheritance) context.getBean("beanInheritance");
    objA.getMessage1();/*ww w .  j  a va 2  s .  c o m*/
    objA.getMessage2();

    BeanChild objB = (BeanChild) context.getBean("beanChild");
    objB.getMessage1();
    objB.getMessage2();
    objB.getMessage3();

    /*
    World Message1 : Hello World!
    World Message2 : Hello Second World!
    India Message1 : Hello India!
    India Message2 : Hello Second World!
    India Message3 : Namaste India!
    */
}

From source file:com.tikal.tallerWeb.control.MainClass.java

public static void main(String arg[]) {
    try {//from   w w  w  . j  a  va  2 s.c om
        ApplicationContext mini = new ClassPathXmlApplicationContext("spring/mini-appContext.xml");
        StartupController startupApp = mini.getBean(StartupController.class);
        startupApp.startup();
    } catch (Exception e) {
        MainClass.LOGGER.error("No se logro inicializar la aplicacion", e);
        System.exit(1);
    }
}

From source file:de.codecentric.example.Application.java

public static void main(String[] args) {
    final ApplicationContext ctx = SpringApplication.run(Application.class);

    final TypeSafeConfiguration typeSafeConfiguration = ctx.getBean(TypeSafeConfiguration.class);
    final AnnotationConfiguration annotationConfiguration = ctx.getBean(AnnotationConfiguration.class);

    info("Application initialized with the following configuration:");
    info(typeSafeConfiguration.toString());
    info(annotationConfiguration.toString());
    System.out.println();/*from ww  w  .  j  a va  2s. co m*/
}

From source file:org.apache.niolex.config.main.ConfigServerMain.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/spring.xml");
    ConfigServer cServer = ctx.getBean(ConfigServer.class);
    if (!cServer.start()) {
        System.out.println("Failed to start Config Server, system will exit...");
        System.exit(-1);/* w ww .  j a  v a2  s. c  o  m*/
    }
    ConnectionWorker.setAuthInfo("d178b4c149");
    BeanServer beanS = new BeanServer();
    beanS.putIfAbsent("os", new OSInfo());
    beanS.putIfAbsent("conf", ctx.getBean(MemoryStorage.class));
    beanS.putIfAbsent("dispatch", ctx.getBean(ConfigEventDispatcher.class));
    beanS.putIfAbsent("server", cServer);
    if (!beanS.start()) {
        System.out.println("Failed to start Bean Server, system will exit...");
        System.exit(-1);
    }
}

From source file:com.apress.prospringintegration.ip.TcpAdapter.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring/ip/tcp-context.xml");
    MessageChannel messageChannel = (MessageChannel) context.getBean("tcpSend");
    messageChannel.send(MessageBuilder.withPayload("Testing TCP").build());
}

From source file:com.apress.prospringintegration.ip.UdpSingle.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring/ip/udp-context.xml");
    MessageChannel messageChannel = (MessageChannel) context.getBean("sendUdp");
    messageChannel.send(MessageBuilder.withPayload("Testing UDP").build());
}

From source file:com.dianping.dpsf.other.echo.SimpleEchoClient.java

/**
 * @param args//from ww  w.ja  va  2 s .c  o  m
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {

    ConfigCache.getInstance("192.168.7.41:2182");
    ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-client.xml");
    IEcho s = (IEcho) ctx.getBean("echo");

    while (true) {
        try {
            System.out.println(s.echo("aa"));
            Thread.sleep(500);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}