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:org.springone2gx_2011.integration.error.ErrorDemo.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("error-config.xml",
            ErrorDemo.class);
    //      ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("error-aggregator-config.xml", ErrorDemo.class);
    ErrorDemoGateway gateway = context.getBean(ErrorDemoGateway.class);
    gateway.process(Arrays.asList("bye", "hello"));
}

From source file:com.apress.prospringintegration.jmx.JmxOperationGateway.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmx/operation-gateway.xml");

    Map<String, Integer> parameters = new HashMap<String, Integer>();
    parameters.put("p1", 5);
    parameters.put("p2", 7);
    MessageChannel request = (MessageChannel) context.getBean("request");
    request.send(MessageBuilder.withPayload(parameters).build());

    try {/* w w  w .  j ava  2  s .c  om*/
        Thread.sleep(180000);
    } catch (InterruptedException e) {
        //do nothing
    }
    context.stop();
}

From source file:org.kuali.student.git.tools.Main.java

/**
 * @param args/*  w w w  .  ja  v  a2  s  .  co  m*/
 */
public static void main(String[] args) {

    if (args.length != 2) {
        log.error("USAGE: <path to git repository> <data file>");
        System.exit(-1);
    }

    String pathToGitRepo = args[0];

    String comparisonTagDataFile = args[1];

    try {

        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "git/applicationContext.xml");

        applicationContext.registerShutdownHook();

        GitExtractor extractor = applicationContext.getBean(GitExtractor.class);

        extractor.buildRepository(new File(pathToGitRepo));

        List<String> pathsToCompare = FileUtils.readLines(new File(comparisonTagDataFile), "UTF-8");

        for (String comparisonPath : pathsToCompare) {

            if (comparisonPath.trim().length() == 0 || comparisonPath.trim().startsWith("#"))
                continue; // skip empty lines and comments

            String parts[] = comparisonPath.split(":");

            String targetTag = parts[0];
            String copyFromTag = parts[1];

            extractor.extractDifference(targetTag, copyFromTag);

        }

    } catch (Exception e) {
        log.error("Unexpected Exception", e);
    }

}

From source file:nl.mindef.c2sc.nbs.olsr.pud.uplink.server.Main.java

public static void main(String[] args) {
    logger.info("RelayServer starting");
    try {//  w ww .  j  a  v a 2s .  co m
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                "classpath:META-INF/spring/application-context.xml");

        logger.info("RelayServer started");

        context.start();

        UplinkReceiver uplinkReceiver = (UplinkReceiver) context.getBean("UplinkReceiver");
        uplinkReceiver.join();

        logger.info("RelayServer stopped");

        context.stop();
        context.close();
        context.destroy();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.berkeley.path.next.trafficMonitor.trafficMonitorApp.java

public static void main(String[] args) throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jms-publish.xml");
    context.start();/*from ww  w  .  java2  s.c  o m*/

    final Logger logger = LogManager.getLogger(trafficMonitorApp.class.getName());

    logger.info("trafficMonitorApp initialized ");

    JmsPublish jmsPublish = context.getBean(JmsPublish.class);

    int x = 0;
    String msg = "status";
    while (x < 7) {
        //use SLF interface which provides for parameterized logging
        logger.info("trafficMonitorApp sendTrafficUpdate {} ", x);
        jmsPublish.sendTrafficUpdate(msg);
        Thread.sleep(3000);
        x++;
    }
}

From source file:nhs.spring.integration.App.java

public static void main(String... args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "spring-integration-context.xml");
    GameMessageHandler gameHandler = new GameMessageHandler();
    GameGenerator gameGenerator = context.getBean(GameGenerator.class);

    context.start();//from  ww w  .j  a  v  a 2 s . c  om

    //MessageChannel input = context.getBean("input-channel", MessageChannel.class);
    //PollableChannel output = context.getBean("output-channel", PollableChannel.class);
    QueueChannel qChannel = context.getBean("game-channel", QueueChannel.class);

    PollingConsumer gameConsumer = new PollingConsumer(qChannel, gameHandler);
    gameConsumer.setReceiveTimeout(RECEIVE_TIMEOUT);
    gameConsumer.setBeanFactory(context);

    // Set up 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);

    gameConsumer.setPollerMetadata(pollerMetadata);

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

    Date today = new Date();

    // Generates messages and sends to the channel
    Game game = gameGenerator.generateGame("League of legend", "Riot Games", today, "Tom", "Michael", "AOS");

    qChannel.send(MessageBuilder.withPayload(game).build());

    /*
    PublishSubscribeChannel pubsubChannel = null;
            
    pubsubChannel.subscribe(gameHandler);
            
    input.send(MessageBuilder.withPayload("Spring Integration / Hello NHS").build());
    Message<?> reply = output.receive();
            
    System.out.println("Received :" + reply);
    */
}

From source file:com.springsource.hq.plugin.tcserver.cli.commandline.Bootstrap.java

/**
 * @param args//w  ww  . j a v  a2 s . c  om
 */
public static void main(final String[] args) {
    try {
        initConnectionProperties(args);
    } catch (Exception e) {
        LOGGER.warn(
                "Error parsing command line connection properties.  Will uses connection properties read from ~/ams/client.properties if present or default values.  Error: "
                        + e.getMessage());
    }
    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "classpath:META-INF/spring/tcsadmin-context.xml" });
    try {
        final int exitCode = ((CommandDispatcher) applicationContext.getBean("commandDispatcher"))
                .dispatch(args);
        System.exit(exitCode);
    } catch (Exception e) {
        System.err.println("Failed to execute command.  Reason: " + e.getMessage());
        System.exit(1);
    }
}

From source file:net.sf.gazpachoquest.codelab.CodeLabRunner.java

public static void main(final String... args) throws IOException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("codelab-datasource-context.xml",
            "codelab-jpa-context.xml", "services-context.xml", "facades-context.xml",
            "questionnaire-context.xml", "components-context.xml");
    logger.info("Hand on lab started");
    AccessRight2Lab codelab = ctx.getBean(AccessRight2Lab.class);
    codelab.execute();//from w ww. j  a  va 2s .c o  m
    logger.info("Hand on lab ended");
    ctx.close();
}

From source file:edu.berkeley.path.next.CTMEngine.CTMEngineApp.java

public static void main(String[] args) throws InterruptedException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ctm-engine.xml");
    context.start();/*from  w  w w .  j a va2  s .  c  o  m*/

    final Logger logger = LogManager.getLogger(CTMEngineApp.class.getName());

    logger.info("trafficMonitorApp initialized ");

    JmsPublish jmsPublish = context.getBean(JmsPublish.class);

    // linkManager creates the data to publish representing ccFramework output
    LinkManager linkManager = context.getBean(LinkManager.class);

    logger.info("trafficMonitorApp initialized ");

    //get a list of output links that we will publish over and over
    java.util.List<LinkDataRaw> links = new ArrayList<LinkDataRaw>();
    links = linkManager.getLinkList();

    logger.info("trafficMonitorApp links to publish: " + links.size());

    //counters
    int x = 0;
    int oneHour = 216000;
    int oneMinute = 3600;

    while (x < oneMinute) {
        //use SLF interface which provides for parameterized logging
        logger.info("CTMEngineApp sendLinkList counter:  " + x);
        jmsPublish.sendLinkList(links);
        //sleep for a third of a second
        //Thread.sleep(10);
        x++;
    }
}

From source file:edu.duke.cabig.c3pr.webservice.subjectmanagement.client.Client.java

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

    SubjectManagement client = (SubjectManagement) context.getBean("subjectManagementClient");

    QuerySubjectRequest request = new QuerySubjectRequest();
    Subject subject = new Subject();
    request.setSubject(subject);
    Person person = new Person();
    subject.setEntity(person);

    // We need to set these to empties in order to pass schema validation on the server side
    // Need to revisit this issue and perhaps change the XSD: setting fields to empties each time
    // does not make a lot of sense.
    person.setAdministrativeGenderCode(new CD());
    person.setBirthDate(new TSDateTime());
    person.setDeathDate(new TSDateTime());
    person.setDeathIndicator(new BL());
    person.setEthnicGroupCode(new DSETCD());
    person.setMaritalStatusCode(new CD());
    person.setName(new DSETENPN());
    person.setPostalAddress(new DSETAD());
    person.setRaceCode(new DSETCD());
    person.setTelecomAddress(new BAGTEL());

    // make repeated requests in a loop to cache things, reduce swapping.
    for (int i = 0; i < 2; i++) {
        client.querySubject(request);
    }

    long start = System.currentTimeMillis();
    QuerySubjectResponse response = executeAndGetResponse(client, request);
    long end = System.currentTimeMillis();

    for (Subject subj : response.getSubjects().getItem()) {
        log.info("Found subject with ID: "
                + subj.getEntity().getBiologicEntityIdentifier().get(0).getIdentifier().getExtension());
    }
    log.info("Total subjects: " + response.getSubjects().getItem().size());
    log.info("Processing time: " + ((end - start) / 1000.0) + " seconds.");

}