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

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

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.dangdang.config.service.easyzk.demo.spring.MainEntrance.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = null;
    try {/* w ww.  j  av  a  2 s.  c  om*/
        context = new ClassPathXmlApplicationContext("classpath:config-toolkit-simple.xml");
        context.registerShutdownHook();
        context.start();

        ExampleBeanWithConfigNode bean = context.getBean(ExampleBeanWithConfigNode.class);
        while (true) {
            bean.someMethod();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                //
            }
        }
    } finally {
        if (context != null) {
            context.close();
        }
    }
}

From source file:com.roncoo.pay.app.settlement.SettTask.java

public static void main(String[] args) {

    try {/*  w  w  w.  j av a  2 s  .  c om*/

        @SuppressWarnings("resource")
        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "spring-context.xml" });
        context.start();
        LOG.debug("");
        SettScheduled settScheduled = (SettScheduled) context.getBean("settScheduled");

        LOG.debug("(??)");
        settScheduled.launchDailySettCollect();
        LOG.debug("(??)?");

        Thread.sleep(MILLIS);

        LOG.debug("()");
        settScheduled.launchAutoSett();
        LOG.debug("()?");

        context.stop();
    } catch (Exception e) {
        LOG.error("SettTask execute error:", e);
    } finally {
        System.exit(0);
        LOG.debug("SettTask Complete");
    }
}

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

/**
 * Runs the tool.//  w  ww. ja va 2s.c  o m
 * 
 * @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:com.jmstoolkit.pipeline.Main.java

/**
 *
 * @param args//w w w  . j a  v a  2s .  co m
 */
public static void main(final String[] args) {
    try {
        Settings.loadSystemSettings("jndi.properties");
        Settings.loadSystemSettings("app.properties");
    } catch (JTKException ex) {
        System.out.println("Failed to load application settings");
        System.out.println(JTKException.formatException(ex));
        System.exit(1);
    }

    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
            "/infrastructure-context.xml", "/mdb-context.xml", "/jmx-context.xml", "/logging-context.xml" });
    applicationContext.start();

    final DefaultMessageListenerContainer dmlc = (DefaultMessageListenerContainer) applicationContext
            .getBean("listenerContainer");
    if (dmlc != null) {
        dmlc.start();
        final Pipeline pipeline = (Pipeline) applicationContext.getBean("pipelineService");
        // enable access to the original application context
        pipeline.setApplicationContext(applicationContext);

        // Insure that the Pipeline loads configuration files AFTER
        // the listenerContainer is running.
        while (!dmlc.isRunning()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
        }
        pipeline.loadPlugins();
        pipeline.sendProperties();
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
        }
    }
}

From source file:com.chaosting.product.hotkey.Main.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    context.start();
    context.close();/*from   w  ww .  j a v  a2  s  .com*/
}

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();

    //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();//  ww  w  . ja v  a2s .c  o m

    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:cn.webank.ecif.index.server.EcifIndexServer.java

/**
 * @param args//from  w  w w .j  ava 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:org.ala.jms.service.JmsListenerService.java

public static void main(String[] args) throws Exception {
    long t = System.currentTimeMillis() + 5000;

    logger.info("Loading ClassPathXmlApplicationContext....... ");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:activemq-context.xml");

    logger.info("ClassPathXmlApplicationContext: " + context);

    // delay for pelpop client stating up
    if (context != null) {

        while (true) {
            if (System.currentTimeMillis() > t) {
                break;
            }//from w w w. j  a  va2  s  . co  m
        }
        context.start();
        logger.info("JMS listener is started!!!");
    }
}

From source file:com.jmstoolkit.pipeline.Pipeline.java

/**
 *
 * @param args the command line arguments
 *//* w w w. j a v  a2s.  c  om*/
public static void main(final String[] args) {
    // Have to use System.out as logging is configured by Spring
    // application context.
    try {
        Settings.loadSystemSettings("jndi.properties");
        Settings.loadSystemSettings("app.properties");
    } catch (JTKException ex) {
        System.out.println("Failed to load application settings");
        System.out.println(JTKException.formatException(ex));
        System.exit(1);
    }

    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
            "/logging-context.xml", "/infrastructure-context.xml", "/mdb-context.xml", "/jmx-context.xml" });
    applicationContext.start();

    final DefaultMessageListenerContainer dmlc = (DefaultMessageListenerContainer) applicationContext
            .getBean("listenerContainer");
    if (dmlc != null) {
        dmlc.start();
        final Pipeline pipeline = (Pipeline) applicationContext.getBean("pipelineService");
        // enable access to the original application context
        pipeline.setApplicationContext(applicationContext);

        // Insure that the Pipeline loads configuration files AFTER
        // the listenerContainer is running.
        while (!dmlc.isRunning()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
        }
        pipeline.loadPlugins();
        pipeline.sendProperties();

        // Keep thread alive
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
        }
    }
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This is the main method./*from   w w w.  j  a  v  a 2 s  . c  o  m*/
 * 
 * @param args {@link String[]}
 */
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/applicationContext-data-access.xml");
    context.start();
    BatchClassService batchClassService = ApplicationContextUtil.getSingleBeanOfType(context,
            BatchClassService.class);
    pluginService = ApplicationContextUtil.getSingleBeanOfType(context, PluginService.class);
    moduleService = ApplicationContextUtil.getSingleBeanOfType(context, ModuleService.class);
    createDBPatch(batchClassService);
}