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:pl.mariuszczarny.springbatchforslask.main.AppJobAllImport.java

/**
 * @param args the command line arguments
 *//*from   w  w  w .j a  v a  2 s .  c o  m*/
public static void main(String[] args) {
    fLogger.log(Level.INFO, "Import all csv to mysql");
    String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml",
            "spring/batch/jobs/job-all-import.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job job = (Job) context.getBean("importJob");

    try {
        JobExecution execution = jobLauncher.run(job, new JobParameters());
        fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus());
    } catch (JobParametersInvalidException e) {
        e.getMessage();
    } catch (JobExecutionAlreadyRunningException e) {
        e.getMessage();
    } catch (JobInstanceAlreadyCompleteException e) {
        e.getMessage();
    } catch (JobRestartException e) {
        e.getMessage();
    }
    fLogger.log(Level.INFO, "Done");
}

From source file:org.springone2gx_2011.integration.segmentation.SegmentationDemo.java

/**
 * @param args//from w w  w .j a  va  2 s  .co m
 */
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("segmentation-config.xml",
            SegmentationDemo.class);
    SegmentOne gateway = context.getBean(SegmentOne.class);
    System.out.println("Result:" + gateway.process(10));

}

From source file:pl.edu.amu.wmi.shop.Shop.java

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

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

    Thread.sleep(1000);//from  ww w.  j  a  v  a  2s. co m

    PublicKey publicKey = ((BankPublicKeyReceiverService) context.getBean("bankPublicKeyReceiverService"))
            .getBankPublicKey();

}

From source file:Spring.Repaso01.Principal.java

public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext("Spring/Repaso01/applicationContext.xml");
    ClienteDAO cdao = (ClienteDAO) context.getBean("ClienteDao");
    Cliente cliente1 = (Cliente) context.getBean("Cliente1");
    Cliente cliente2 = (Cliente) context.getBean("Cliente2");

    cdao.alta(cliente1);//from www  .j  a  va2 s  . c o m
    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 (Spring.Repaso01.Cliente c : cdao.consultaTodos()) {
        System.out.println(c.toString());
    }
    if (cdao.consultaTodos().isEmpty())
        System.out.println("Array vacio.");

}

From source file:edu.eci.cosw.samples.logic.Main.java

public static void main(String[] args) {
    ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    ServiceFacade sf = ac.getBean(ServiceFacade.class);
    List<Cliente> clientes = null;
    try {//from   w  ww . j a  va2 s.  c  om
        clientes = sf.clientesReportadosPorApellido("var");
    } catch (ClientEvaluationException ex) {
        System.out.println("Fallo consulta por apellido");
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (clientes != null) {
        for (Cliente c : clientes) {
            System.out.println(
                    c.getIdcliente() + " " + c.getNombre() + " " + c.getDireccion() + " " + c.getTelefono());
        }
    }
    try {
        //Registrar un nuevo cliente
        sf.registrarCliente(1072672, "Guillermo Alvarez", "Calle 3#3E-116", "1234567");
    } catch (ClientEvaluationException ex) {
        System.out.println("Fallo insercion");
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Crear un pedido
    Date d = new Date(2015 - 1900, 8, 23);
    int[] idProductos = { 1 };
    int[] cantidades = { 3 };
    sf.registrarPedido(1072672, idProductos, cantidades, d);
    //Mirar en la base de datos que se creo el pedido de este cliente     
    try {
        //Consulta Fallida
        sf.registrarCliente(333, "Luis Alvarez", "Calle 3E#3-116", "1234567");
    } catch (ClientEvaluationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mkyong.AppJobCityImport.java

/**
 * @param args the command line arguments
 *//*from   w w  w  .j a va 2  s.c o  m*/
public static void main(String[] args) {
    fLogger.log(Level.INFO, "Import city csv from mysql");
    String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml",
            "spring/batch/jobs/csvimport/job-city-import.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobCityLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job cityJob = (Job) context.getBean("cityImportJob");

    try {
        JobExecution execution = jobCityLauncher.run(cityJob, new JobParameters());
        fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus());
    } catch (JobParametersInvalidException e) {
        e.getMessage();
    } catch (JobExecutionAlreadyRunningException e) {
        e.getMessage();
    } catch (JobInstanceAlreadyCompleteException e) {
        e.getMessage();
    } catch (JobRestartException e) {
        e.getMessage();
    }
    fLogger.log(Level.INFO, "Done");
}

From source file:com.mkyong.AppJobReportImport.java

/**
 * @param args the command line arguments
 *///w ww  . j  av a2  s.  co m
public static void main(String[] args) {
    fLogger.log(Level.INFO, "Import report csv from mysql");
    String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml",
            "spring/batch/jobs/csvimport/job-report-import.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobCityLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job reportJob = (Job) context.getBean("reportImportJob");

    try {
        JobExecution execution = jobCityLauncher.run(reportJob, new JobParameters());
        fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus());
    } catch (JobParametersInvalidException e) {
        e.getMessage();
    } catch (JobExecutionAlreadyRunningException e) {
        e.getMessage();
    } catch (JobInstanceAlreadyCompleteException e) {
        e.getMessage();
    } catch (JobRestartException e) {
        e.getMessage();
    }
    fLogger.log(Level.INFO, "Done");
}

From source file:org.italiangrid.storm.webdav.server.Main.java

public static void main(String[] args) {

    StatusPrinter.printInCaseOfErrorsOrWarnings((LoggerContext) LoggerFactory.getILoggerFactory());

    log.info("StoRM WebDAV server v. {}", Version.version());

    @SuppressWarnings("resource")
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    ServerLifecycle server = context.getBean(ServerLifecycle.class);
    server.start();// w  w w.j a v  a 2  s.  co m

}

From source file:pl.mariuszczarny.springbatchforslask.main.fromcsv.ArrangeExport.java

/**
 * @param args the command line arguments
 *//*from w ww . j  a  v  a  2  s  .  c o m*/
public static void main(String[] args) {
    fLogger.log(Level.INFO, "Import city csv from mysql");
    String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml",
            "spring/batch/jobs/fromdb/city.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobCityLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job cityJob = (Job) context.getBean("cityImportJob");

    try {
        JobExecution execution = jobCityLauncher.run(cityJob, new JobParameters());
        fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus());
    } catch (JobParametersInvalidException e) {
        e.getMessage();
    } catch (JobExecutionAlreadyRunningException e) {
        e.getMessage();
    } catch (JobInstanceAlreadyCompleteException e) {
        e.getMessage();
    } catch (JobRestartException e) {
        e.getMessage();
    }
    fLogger.log(Level.INFO, "Done");
}

From source file:pl.mariuszczarny.springbatchforslask.main.fromdb.ClubImport.java

/**
 * @param args the command line arguments
 *//* ww w.  j  av  a2 s  . c  o  m*/
public static void main(String[] args) {
    fLogger.log(Level.INFO, "Import club csv from mysql");
    String[] springConfig = { "spring/batch/config/database.xml", "spring/batch/config/context.xml",
            "spring/batch/jobs/fromdb/club.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobCityLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job clubJob = (Job) context.getBean("clubImportJob");

    try {
        JobExecution execution = jobCityLauncher.run(clubJob, new JobParameters());
        fLogger.log(Level.INFO, "Exit Status : {0}", execution.getStatus());
    } catch (JobParametersInvalidException e) {
        e.getMessage();
    } catch (JobExecutionAlreadyRunningException e) {
        e.getMessage();
    } catch (JobInstanceAlreadyCompleteException e) {
        e.getMessage();
    } catch (JobRestartException e) {
        e.getMessage();
    }
    fLogger.log(Level.INFO, "Done");
}