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 <T> T getBean(String name, Class<T> requiredType) throws BeansException 

Source Link

Usage

From source file:com.edmunds.etm.tools.urltoken.application.UrlTokenTool.java

public static void main(String[] args) {
    // Create the Spring application context
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("etm-url-token-tool-context.xml");

    // Run the Apache agent
    UrlTokenTool tokenTool;//from w w  w .j ava 2 s.c om
    tokenTool = (UrlTokenTool) ctx.getBean("urlTokenTool", UrlTokenTool.class);
    tokenTool.run(args);
}

From source file:no.trank.openpipe.tutorial.intranet.Main.java

public static void main(String[] args) {
    if (args.length < 1) {
        usage();//from   w w  w.  j  a  va 2  s  .co m
    } else {
        try {
            ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
                    "intranetApplicationContext.xml");
            try {
                FileDocumentReader directory = (FileDocumentReader) appContext.getBean("fileDocumentReader",
                        FileDocumentReader.class);
                directory.setDirectory(args[0]);

                if (args.length > 1) {
                    SolrHttpDocumentPoster solrDocumentPoster = (SolrHttpDocumentPoster) appContext
                            .getBean("solrDocumentPoster", SolrHttpDocumentPoster.class);
                    SolrDocumentProcessor solrDocumentProcessor = (SolrDocumentProcessor) appContext
                            .getBean("solrDocumentProcessor", SolrDocumentProcessor.class);

                    String solrUrl = args[1];
                    solrDocumentPoster.setPostUrl(solrUrl + "/update");
                    solrDocumentProcessor.setSolrSchemaUrl(solrUrl + "/admin/get-file.jsp?file=schema.xml");
                }

                Runnable pipelineApplication = (Runnable) appContext.getBean("pipelineApplicationBean",
                        Runnable.class);
                pipelineApplication.run();
            } finally {
                appContext.close();
            }
        } catch (BeansException e) {
            log.error("Spring error", e);
        }
    }
}

From source file:com.apress.prospringintegration.gateways.client.MainJMSGateway.java

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

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/pro-spring-integration/gateway-jms-service.xml",
            "/META-INF/spring/integration/pro-spring-integration/common.xml");

    ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/pro-spring-integration/gateway-jms-client.xml",
            "/META-INF/spring/integration/pro-spring-integration/common.xml");

    TicketIssuer ticketIssuer = ctx1.getBean("ticketIssueGateway", TicketIssuer.class);

    for (int i = 0; i < 20; i++) {
        Ticket ticket = ticketIssuer.issueTicket(i);

        System.out.println("Ticket " + ticket + " was issued on:" + ticket.getIssueDateTime()
                + " with ticket id: " + ticket.getTicketId());

    }//from ww  w . j  a v  a  2 s  . co m
}

From source file:com.opengamma.bbg.referencedata.cache.MongoDBReferenceDataCacheRefresher.java

/**
 * Runs the tool.// w ww.  java2 s.  c om
 * 
 * @param args  empty arguments
 * @throws Exception 
 */
public static void main(final String[] args) throws Exception { // CSIGNORE
    PlatformConfigUtils.configureSystemProperties();
    System.out.println("Starting connections");
    String configLocation = "com/opengamma/bbg/bbg-reference-data-context.xml";

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
    try {
        context.start();
        MongoDBValueCachingReferenceDataProvider mongoProvider = context
                .getBean("bloombergReferenceDataProvider", MongoDBValueCachingReferenceDataProvider.class);
        MongoDBReferenceDataCacheRefresher refresher = new MongoDBReferenceDataCacheRefresher(mongoProvider);

        Options options = createOptions();
        CommandLineParser parser = new PosixParser();
        CommandLine line = null;
        try {
            line = parser.parse(options, args);
        } catch (ParseException e) {
            usage(options);
            return;
        }
        if (line.hasOption(HELP_OPTION)) {
            usage(options);
            return;
        }

        //TODO other options, e.g. explicitly specify security 
        int numberOfSecurities = Integer.parseInt(line.getArgs()[0]);
        int id = Integer.parseInt(line.getArgs()[1]);
        System.out.println("Refreshing " + numberOfSecurities + " securities, id " + id);
        refresher.refreshCaches(numberOfSecurities, id);
        System.out.println("Done refreshing");
    } catch (Exception ex) {
        context.close();
        throw ex;
    }
}

From source file:Neo4JDataImporter.java

public static void main(String[] args) throws Exception {
    /*//www.  j  a v a 2s  .c  om
    org.neo4j.rest.read_timeout=30
    org.neo4j.rest.connect_timeout=30
    org.neo4j.rest.driver="neo4j-rest-graphdb/1.8.RC1"
    org.neo4j.rest.stream=true
    org.neo4j.rest.batch_transactions=false (convert transaction scope into batch-rest-operations)
    org.neo4j.rest.logging_filter=false (set to true if verbose request/response logging should be enabled)
            
    org.neo4j.rest.read_timeout=30
    * org.neo4j.rest.connect_timeout=30
    * org.neo4j.rest.driver="neo4j-rest-graphdb/1.8M07"
    * org.neo4j.rest.stream=true
    * */
    System.setProperty("org.neo4j.rest.read_timeout", "30");
    System.setProperty("org.neo4j.rest.connect_timeout", "30");
    System.setProperty("org.neo4j.rest.driver", "neo4j-rest-graphdb/1.8.RC1");
    System.setProperty("org.neo4j.rest.stream", "true");
    System.setProperty("org.neo4j.rest.batch_transactions", "true");
    System.setProperty("org.neo4j.rest.logging_filter", "false");
    //        org.springframework.data.neo4j.rest.SpringRestGraphDatabase     d;
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("neo4j-spring.xml");
    GraphDatabaseService graphdb = applicationContext.getBean("graphDbService", GraphDatabaseService.class);
    //        GraphDatabaseService gds = new RestGraphDatabase("http://localhost:7474/db/data");
    //        GraphDatabaseService graphdb = new RestGraphDatabase("http://localhost:7474/db/data",username,password);
    doImport(graphdb);

}

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

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

    try {//from w  w  w.  j  a  v a  2s. c o  m
        Thread.sleep(60000);
    } catch (InterruptedException e) {
        //do nothing
    }

    System.out.println("Sending message");
    MessageChannel send = context.getBean("send", MessageChannel.class);
    send.send(MessageBuilder.withPayload("Sample Message").build());

    try {
        Thread.sleep(180000);
    } catch (InterruptedException e) {
        //do nothing
    }
    context.stop();
}

From source file:cn.webank.ecif.index.server.EcifIndexServer.java

/**
 * @param args/*w  w  w .  ja v  a  2 s  . c o m*/
 */
public static void main(String[] args) {
    final EcifIndexServer server = new EcifIndexServer();
    // start spring context;
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();

    context.getEnvironment().setActiveProfiles("product");
    context.setConfigLocation("application.xml");
    context.refresh();
    context.start();

    // thread pool construct
    ThreadPoolTaskExecutor taskThreadPool = context.getBean("taskExecutor", ThreadPoolTaskExecutor.class);

    server.setTaskThreadPool(taskThreadPool);

    ExecutorService fixedThreadPool = context.getBean("fixedTaskExecutor", ExecutorService.class);

    server.setSchedulerThreadPool(fixedThreadPool);

    EcifThreadFactory threadFactory = context.getBean("cn.webank.ecif.index.async.EcifThreadFactory",
            EcifThreadFactory.class);

    server.setThreadFactory(threadFactory);

    Properties props = context.getBean("ecifProperties", java.util.Properties.class);

    WeBankServiceDispatcher serviceDispatcher = context.getBean(
            "cn.webank.framework.biz.service.support.WeBankServiceDispatcher", WeBankServiceDispatcher.class);

    ReloadableResourceBundleMessageSource bundleMessageSource = context.getBean("messageSource",
            ReloadableResourceBundleMessageSource.class);

    String topics = props.getProperty("listener.topics");
    String[] splits = topics.split(",");

    SolaceManager solaceManager = context.getBean("cn.webank.framework.message.SolaceManager",
            SolaceManager.class);
    MessageListener messageLisener = new MessageListener(
            // props.getProperty("listener.queue"),
            Arrays.asList(splits), Integer.parseInt(props.getProperty("listener.scanintervalseconds", "5")),
            taskThreadPool, Integer.parseInt(props.getProperty("listener.timeoutseconds", "5")),
            serviceDispatcher, solaceManager, bundleMessageSource);
    server.addListenerOnSchedule(messageLisener);

    // register shutdownhook
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                // close resource
                if (context != null) {
                    context.close();
                }

            } catch (Exception e) {
                LOG.error("shutdown error", e);
            }
        }
    });

    // hold server
    try {
        LOG.info("ecif-index server start ok!");
        server.start();
    } catch (Exception e) {
        try {
            // close resource
            server.shutDown();
            if (context != null) {
                context.close();
            }

        } catch (Exception ex) {
            LOG.error("shutdown error", ex);
        }
    }

    LOG.info("ecif-index server stop !");
}

From source file:com.codeasylum.stress.ui.Jormungandr.java

public static void main(String... args) {

    boolean init = false;

    try {/*from w w w .j  ava2  s  .  c  o m*/
        new ExtendedTaskLoader();
        init = true;
    } catch (Exception exception) {
        JavaErrorDialog.showJavaErrorDialog(null, null, exception);
    }

    if (init) {

        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/codeasylum/stress/api/logging.xml", "com/codeasylum/stress/ui/jormungandr.xml");

        Jormungandr jormungandr = applicationContext.getBean("jormungandr", Jormungandr.class);

        try {
            jormungandr.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {

                    applicationContext.close();

                }
            });

            jormungandr.init().setVisible(true);
        } catch (Exception exception) {
            JavaErrorDialog.showJavaErrorDialog(jormungandr, jormungandr, exception);
            jormungandr.dispose();
        }
    }
}

From source file:fr.itinerennes.bundler.cli.GtfsItinerennesBundler.java

/**
 * @param args//from  w  w w.  j  a  va2  s .  co m
 */
public static void main(final String[] args) throws IOException {

    final GtfsItinerennesBundler main = new GtfsItinerennesBundler();
    main.parseCmdLine(args);

    ClassPathXmlApplicationContext bootCtx = null;
    ClassPathXmlApplicationContext ctx = null;
    try {
        LOGGER.info("Initialization...");
        // pre-context dynamically initialize some beans depending on program args
        bootCtx = new ClassPathXmlApplicationContext("classpath:/boot-context.xml");
        main.loadArguments(bootCtx.getBean("programArgs", Properties.class));
        bootCtx.getBean("agencyMapping", Map.class).putAll(main.agencyMapping);

        ctx = new ClassPathXmlApplicationContext(new String[] { "classpath:/application-context.xml" },
                bootCtx);
        LOGGER.info("Application context initialization finished");

        if (main.listTasks) {
            main.listTasksAndExit(ctx);
        }

        final List<AbstractTask> selectedTasks = main.verifySelectedTasksExists(ctx);
        LOGGER.info("Start tasks execution...");
        main.execute(selectedTasks);
        LOGGER.info("Tasks execution finished");
    } finally {
        IOUtils.closeQuietly(ctx);
        IOUtils.closeQuietly(bootCtx);
    }
}

From source file:com.codeasylum.liquibase.Liquidate.java

public static void main(String... args) {

    ExtendedProfileLoader extensionLoader = null;
    boolean init = false;

    try {//from  ww  w  . j a v  a  2 s .  c  o  m
        extensionLoader = new ExtendedProfileLoader();
        init = true;
    } catch (Exception exception) {
        JavaErrorDialog.showJavaErrorDialog(null, null, exception);
    }

    if (init) {

        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/codeasylum/liquibase/liquidate.xml");

        Liquidate liquidate = applicationContext.getBean("liquidate", Liquidate.class);

        try {
            liquidate.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {

                    applicationContext.close();

                }
            });

            liquidate.init(extensionLoader).setVisible(true);
        } catch (Exception exception) {
            JavaErrorDialog.showJavaErrorDialog(liquidate, liquidate, exception);
            liquidate.dispose();
        }
    }
}