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.softserveinc.internetbanking.testit.JDBCtemplateMoneyTransaction.java

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

    MoneyTransactionJDBCTemplate moneyTransactionJDBCTemplate = (MoneyTransactionJDBCTemplate) context
            .getBean("moneyTransactionJDBCTemplate");

    System.out.println("------Records Creation--------");
    BigDecimal number = new BigDecimal("200.00");
    moneyTransactionJDBCTemplate.createTransaction(1, 3, number);
    moneyTransactionJDBCTemplate.createTransaction(1, 3, number);

}

From source file:koper.reactor.demo.CustomerApp.java

public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:kafka/context-data-consumer.xml");
    ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class);
    // we have close the switch in context-data-consumer.xml profile(autoStart) temporary
    consumerLauncher.start();/*from  w ww .j  a  v a  2  s .  c  om*/
}

From source file:org.springone2gx_2011.integration.gatewaywithtimeout.EchoGatewayDemo.java

/**
 * @param args/*from w  w  w.  j  a v a 2  s .com*/
 */
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("gateway-with-timeout-config.xml",
            EchoGatewayDemo.class);
    final EchoGateway gateway = context.getBean(EchoGateway.class);
    System.out.println(gateway.echo("foo"));
    System.out.println(gateway.echo("bar"));
}

From source file:com.jbrisbin.vcloud.cache.Bootstrap.java

public static void main(String[] args) {

    CommandLineParser parser = new BasicParser();
    CommandLine cmdLine = null;//  ww w.ja  v a2 s .co m
    try {
        cmdLine = parser.parse(opts, args);
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
    }

    String configFile = "/etc/cloud/async-cache.xml";
    if (null != cmdLine) {
        if (cmdLine.hasOption('c')) {
            configFile = cmdLine.getOptionValue('c');
        }
    }

    ApplicationContext context = new FileSystemXmlApplicationContext(configFile);
    RabbitMQAsyncCacheProvider cacheProvider = context.getBean(RabbitMQAsyncCacheProvider.class);
    while (cacheProvider.isActive()) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e);
        }
    }

}

From source file:springaspect01.Principal.java

/**
 * @param args the command line arguments
 *///from   www  . j  av  a 2s .co m
public static void main(String[] args) {
    // TODO code application logic here
    ApplicationContext context = new ClassPathXmlApplicationContext("springaspect01/applicationContext.xml");
    ClienteDAO cdao = (ClienteDAO) context.getBean("ClienteDao");
    Cliente cliente1 = (Cliente) context.getBean("Cliente1");
    Cliente cliente2 = (Cliente) context.getBean("Cliente2");

    cdao.alta(cliente1);
    for (Cliente c : cdao.consultaTodos()) {
        System.out.println(c.toString());
    }
    cdao.modificacion(cliente2);
    for (Cliente c : cdao.consultaTodos()) {
        System.out.println(c.toString());
    }
    System.out.println(cdao.consulta(cliente1.getIdCliente()).toString());
    cdao.baja(cliente1.getIdCliente());
    for (Cliente c : cdao.consultaTodos()) {
        System.out.println(c.toString());
    }
    if (cdao.consultaTodos().isEmpty())
        System.out.println("Array vacio.");

}

From source file:uk.ac.ebi.ricordo.rdfconverter.ReactomeMain.java

public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:reactome-config.xml");
    ReactometoRDFGenerator reactometoRDFGenerator = (ReactometoRDFGenerator) ctx
            .getBean("reactometoRDFGenerator");
    //        reactometoRDFGenerator.aModeltoRDF();
    reactometoRDFGenerator.allModelstoRDF();
}

From source file:com.anton.dev.tqrbs2.QueuePublishProcess.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    QueuePublishProcess publisher = context.getBean(QueuePublishProcess.class);
    publisher.setup();//from www  .ja va  2s  . co  m
    publisher.publish();
}

From source file:org.jboss.narayana.quickstart.spring.QuickstartApplication.java

public static void main(String[] args) throws Exception {
    if (args.length != 1 && args.length != 2) {
        throw new IllegalArgumentException("Invalid arguments provided. See README.md for usage examples");
    } else if (args.length == 1 && !args[0].toUpperCase().equals(CompleteAction.RECOVERY.name())) {
        throw new IllegalArgumentException("Invalid arguments provided. See README.md for usage examples");
    }/*from   www . j a  v  a 2  s  .  c  o m*/

    ApplicationContext context = SpringApplication.run(QuickstartApplication.class, args);
    QuickstartService quickstartService = context.getBean(QuickstartService.class);

    switch (CompleteAction.valueOf(args[0].toUpperCase())) {
    case COMMIT:
        quickstartService.demonstrateCommit(args[1]);
        break;
    case ROLLBACK:
        quickstartService.demonstrateRollback(args[1]);
        break;
    case CRASH:
        quickstartService.demonstrateCrash(args[1]);
        break;
    case RECOVERY:
        quickstartService.demonstrateRecovery();
    }

    ((Closeable) context).close();
}

From source file:org.springintegration.NotificationListener.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/spring/integration/remote-monitor-context.xml");
    Gateway gw = ctx.getBean(Gateway.class);
    int cmd = 0;/*from  w w w  . j  av  a  2 s.  co  m*/
    while (cmd != 'q') {
        cmd = System.in.read();
        gw.send((char) cmd);
    }
}

From source file:delete_tcp.java

public static void main(String ar[]) throws IOException {
    ServerSocket ss = new ServerSocket(9999);

    Socket s = ss.accept();//from w ww.  j  a va2 s . c  om

    DataInputStream in = new DataInputStream(s.getInputStream());
    DataOutputStream out = new DataOutputStream(s.getOutputStream());

    String id = in.readUTF();

    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

    EmployeeJDBCTemplate employeeJDBCTemplate = (EmployeeJDBCTemplate) context.getBean("employeeJDBCTemplate");

    System.out.println("Deleting Records...");

    employeeJDBCTemplate.delete(Integer.parseInt(id));

    out.writeUTF("Success");

    s.close();

}