Example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean

Introduction

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

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:com.alibaba.dubbo.examples.heartbeat.HeartbeatConsumer.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            HeartbeatConsumer.class.getPackage().getName().replace('.', '/') + "/heartbeat-consumer.xml");
    context.start();/*from   w  ww .j  a v  a  2 s.c  o m*/
    HelloService hello = (HelloService) context.getBean("helloService");
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        System.out.println(hello.sayHello("kimi-" + i));
        Thread.sleep(10000);
    }
}

From source file:org.excalibur.fm.configuration.MainConsole.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:META-INF/applicationContext.xml");
    final ProviderService providerService = context.getBean(ProviderService.class);

    // get all instance types offered at the North America region of all providers
    InstanceTypes instanceTypes = new InstanceTypes(
            providerService.getInstanceTypesAvailableOnRegion(GeographicRegions.NORTH_AMERICA.toType()));

    // get all instance types of all regions of all providers
    instanceTypes = new InstanceTypes(providerService.getAllInstanceTypesOfAllRegions());

    Constraint[] constraints = new Constraint[] { new Constraint(new Variable("cores", 9), Operator.GE),
            new Constraint(new Variable("memory", 4 * 1024), Operator.GE),
            new Constraint(new Variable("cost", 1000), Operator.LE) };

    InstanceTypes allSolutions = new InstanceSelection(instanceTypes).findAllSolutions(constraints);

    InstanceTypes allOptimalSolutions = new InstanceSelection(instanceTypes)
            .findAllOptimalSolutions(ResolutionPolicy.MINIMIZE, constraints, COST);

    InstanceTypes paretoFront = new InstanceSelection(instanceTypes).findParetoFront(ResolutionPolicy.MAXIMIZE,
            constraints, CORES.getName(), MEMORY.getName());

    System.out.format("\n%36s%13s%36s\n\n", " ", "All solutions", " ");
    print(allSolutions);/*from   www  . ja  v  a 2 s .  com*/

    System.out.format("\n%33s%17s%33s\n\n", " ", "Optimal solutions", " ");
    print(allOptimalSolutions);

    System.out.format("\n%36s%13s%36s\n\n", " ", "Pareto front", " ");
    print(paretoFront);
}

From source file:com.apress.prospringintegration.springbatch.integration.Main.java

public static void main(String[] args) throws Throwable {
    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
            "integration.xml");
    classPathXmlApplicationContext.start();

    JobLauncher jobLauncher = (JobLauncher) classPathXmlApplicationContext.getBean("jobLauncher");
    Job job = (Job) classPathXmlApplicationContext.getBean("importData");

    JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
    jobParametersBuilder.addDate("date", new Date());
    jobParametersBuilder.addString("input.file", "registrations");
    JobParameters jobParameters = jobParametersBuilder.toJobParameters();

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    BatchStatus batchStatus = jobExecution.getStatus();
    while (batchStatus.isRunning()) {
        System.out.println("Still running...");
        Thread.sleep(1000);/*from  w  ww .  j a v  a  2  s  .com*/
    }

    System.out.println("Exit status: " + jobExecution.getExitStatus().getExitCode());
    JobInstance jobInstance = jobExecution.getJobInstance();
    System.out.println("job instance Id: " + jobInstance.getId());
}

From source file:com.apress.prospringintegration.messageflow.workflow.WorkflowMainClient.java

public static void main(String[] ars) throws Exception {
    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
            "workflow-gateway.xml");
    classPathXmlApplicationContext.start();

    ProcessEngine processEngine = classPathXmlApplicationContext.getBean(ProcessEngine.class);

    deployProcessDefinitions(processEngine, "processes/hello.bpmn20.xml", "processes/gateway.bpmn20.xml");

    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("customerId", 2);

    ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("sigateway",
            processVariables);//from   w ww  .j a  v  a  2  s .  c  o  m

    log.debug("the process instance has been started: PI ID # " + pi.getId());

    Thread.sleep(1000 * 20);
    log.debug("waited 20s");
}

From source file:demo.hw.client.SpringClient.java

public static void main(String args[]) throws Exception {
    // START SNIPPET: client
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "/demo/hw/client/client-beans.xml" });

    Greeter port = (Greeter) context.getBean("client");

    String resp;// w w w.j  a v  a  2s.  c  om

    System.out.println("Invoking sayHi...");
    resp = port.sayHi();
    System.out.println("Server responded with: " + resp);
    System.out.println();

    System.out.println("Invoking greetMe...");
    resp = port.greetMe(System.getProperty("user.name"));
    System.out.println("Server responded with: " + resp);
    System.out.println();

    System.out.println("Invoking greetMe with invalid length string, expecting exception...");
    try {
        resp = port.greetMe("Invoking greetMe with invalid length string, expecting exception...");
    } catch (WebServiceException ex) {
        System.out.println("Caught expected WebServiceException:");
        System.out.println("    " + ex.getMessage());
    }

    System.out.println();

    System.out.println("Invoking greetMeOneWay...");
    port.greetMeOneWay(System.getProperty("user.name"));
    System.out.println("No response from server as method is OneWay");
    System.out.println();

    try {
        System.out.println("Invoking pingMe, expecting exception...");
        port.pingMe();
    } catch (PingMeFault ex) {
        System.out.println("Expected exception: PingMeFault has occurred: " + ex.getMessage());
        FaultDetailDocument detailDocument = ex.getFaultInfo();
        FaultDetail detail = detailDocument.getFaultDetail();
        System.out.println("FaultDetail major:" + detail.getMajor());
        System.out.println("FaultDetail minor:" + detail.getMinor());
    }

    System.exit(0);
    // END SNIPPET: client
}

From source file:com.apress.prospringintegration.endpoints.pollingconsumer.Main.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "polling-consumer.xml");
    applicationContext.start();//from w ww.j av  a2 s. co  m

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);

    QueueChannel channel = applicationContext.getBean("ticketChannel", QueueChannel.class);

    // Define the polling consumer
    PollingConsumer ticketConsumer = new PollingConsumer(channel, ticketMessageHandler);
    ticketConsumer.setReceiveTimeout(RECEIVE_TIMEOUT);
    ticketConsumer.setBeanFactory(applicationContext);

    // Setup the poller using periodic trigger
    PeriodicTrigger periodicTrigger = new PeriodicTrigger(1000);
    periodicTrigger.setInitialDelay(5000);
    periodicTrigger.setFixedRate(false);

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(periodicTrigger);
    pollerMetadata.setMaxMessagesPerPoll(3);

    ticketConsumer.setPollerMetadata(pollerMetadata);

    // Starts the polling consumer in the other thread
    ticketConsumer.start();

    // Generates messages and sends to the channel
    List<Ticket> tickets = ticketGenerator.createTickets();
    while (true) {
        for (Ticket ticket : tickets) {
            problemReporter.openTicket(ticket);
        }
    }
}

From source file:net.sf.gazpachoquest.exporter.ExporterRunner.java

public static void main(final String... args) throws IOException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("exporter-datasource-context.xml",
            "exporter-jpa-context.xml", "services-context.xml", "facades-context.xml",
            "components-context.xml");
    Exporter exporter = ctx.getBean(Exporter.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Exporting questionnaire definition");
    stopWatch.start();//from w w w . j  a v a2 s . c om
    exporter.doExport();
    stopWatch.stop();
    logger.info("Export process ended in {} {}", stopWatch.getTime(), "ms");
    ctx.close();
}

From source file:tetrad.rrd.TestGraph.java

/**
 * @param args//from   w w  w  .j a v  a 2  s  . c  om
 */
public static void main(String[] args) {
    String[] configLocations = new String[] { "applicationContext_rrd.xml" };
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocations);

    TetradRrdDbService rrd = (TetradRrdDbService) context.getBean("tetradRrdDbService");

    TestGraph testGraph = new TestGraph();
    GraphDefInfo graph = testGraph.getGraphDefInfo();
    graph.setFileName("tt");
    //      rrd.graphPerRrdDb("dbDataSize", graph);
    //      rrd.graphRrdDbGroup(graph);
    //      rrd.graphTetradRrdDb(graph);

    testGraph.fetchTetradRrdDb("dbDataSize", graph.getStartTime(), graph.getEndTime());
}

From source file:net.sf.gazpachoquest.importer.ImporterRunner.java

public static void main(final String... args) throws IOException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("importer-datasource-context.xml",
            "importer-jpa-context.xml", "services-context.xml", "facades-context.xml",
            "components-context.xml");
    Importer populator = ctx.getBean(Importer.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Importing questionnaire definitions");
    stopWatch.start();//from   ww  w  . j ava 2s  .c  o  m
    populator.doImport();
    stopWatch.stop();
    logger.info("Import process ended in {} {}", stopWatch.getTime(), "ms");
    ctx.close();
}

From source file:demo.order.client.CxfApp.java

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

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            new String[] { "demo/order/client/client-beansRh.xml" });

    CxfApp cxf = (CxfApp) ctx.getBean("cxfApp");

    MsgSender sender = (MsgSender) ctx.getBean("msgSenderClient");
    MsgWrapper wrap = new MsgWrapper();
    wrap.setMsg("KOKOSKO");
    wrap.setQueue("queue1");
    sender.sendMessage(wrap);//from ww w.ja v  a 2s  .  c  o  m
    //        cxf.sendMsg("KOKOSKO", "queue1");
    //        cxf.deliverMsg("queue1");
}