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

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

Introduction

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

Prototype

@Override
    public <T> T getBean(Class<T> requiredType) throws BeansException 

Source Link

Usage

From source file:com.springdeveloper.hadoop.hive.HiveApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hive-context.xml",
            HiveApp.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();//w  w  w.  j a va  2  s.c  o  m

    HiveTemplate template = context.getBean(HiveTemplate.class);

    HiveScript script = new HiveScript(new ClassPathResource("tweet-influencers.hql"));

    template.executeScript(script);

    context.close();
}

From source file:net.cit.tetrad.rrd.batch.InputForTetradRrd.java

public static void main(String[] args) {
    try {//from  w  w  w.java2  s. c  o m
        logger.debug("InputForTetradRrd Start!!");

        // ? ?? ?
        String[] configLocations = new String[] { XML_PATH + "applicationContext_management.xml",
                "applicationContext-mongo.xml", "applicationContext_rrd.xml" };
        AbstractApplicationContext context = new ClassPathXmlApplicationContext(configLocations);

        // TetradRrd? ??   ? ?
        TetradRrdInitializer tetradRrdInitializer = (TetradRrdInitializer) context
                .getBean("tetradRrdInitializer");
        tetradRrdInitializer.input();

        logger.debug("InputForTetradRrd End!!");
    } catch (Exception e) {
        logger.info("----------------------------------------------------------------");
        logger.info(e.getMessage());
        logger.info("----------------------------------------------------------------");
    }
}

From source file:org.javadude.trade.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from   ww w  .  j a v  a  2  s.  com*/
 */
public static void main(final String... args) {

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    ITradeProcessor service = context.getBean(ITradeProcessor.class);

    Trade t = new Trade("T001", "P001", "TUSINAPP", "Apple Inc.", "");
    Validation validation = Validation.getInstance();
    validation.setTrade(t);
    try {

        Message<?> m = service.processTrade(MessageBuilder.withPayload(validation).build());
        //String msg = (String);
        System.out.println("Final Trade : " + m.getPayload());

    } catch (Exception e) {
        LOGGER.error("An exception was caught: " + e);
    }

}

From source file:com.oreilly.springdata.hadoop.hbase.UserApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/application-context.xml", UserApp.class);
    log.info("HBase Application Running");
    context.registerShutdownHook();//from   w  ww. j a  v  a  2s .  com

    UserUtils userUtils = context.getBean(UserUtils.class);
    userUtils.initialize();
    userUtils.addUsers();

    UserRepository userRepository = context.getBean(UserRepository.class);
    List<User> users = userRepository.findAll();
    System.out.println("Number of users = " + users.size());
    System.out.println(users);

}

From source file:com.aan.girsang.client.launcher.ClientLauncher.java

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

    BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
    org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
    UIManager.put("RootPane.setupButtonVisible", Boolean.FALSE);

    try {/*from ww w  .  java 2  s  .c  o m*/
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("clientContext.xml");
        ctx.registerShutdownHook();

        constantService = (ConstantService) ctx.getBean("constantServiceRemote");
        securityService = (SecurityService) ctx.getBean("securityServiceRemote");
        masterService = (MasterService) ctx.getBean("masterServiceRemote");
        transaksiService = (TransaksiService) ctx.getBean("transaksiServiceRemote");
        reportService = (ReportService) ctx.getBean("reportServiceRemote");
        String computerName = InetAddress.getLocalHost().getHostName();

        constantService.clientOnline(computerName);
    } catch (RemoteConnectFailureException ex) {
        String status = "Server Offline";
        ex.printStackTrace();
        log.info(ex.getMessage());
        JOptionPane.showMessageDialog(null, status);
        System.exit(0);
    }
    log.info("Client Online");

    java.awt.EventQueue.invokeLater(() -> {
        FrameUtama fu = new FrameUtama();
        fu.setExtendedState(JFrame.MAXIMIZED_BOTH);
        fu.setVisible(true);
        fu.jam();
    });
}

From source file:com.ifeng.vdn.web.hive.HiveApp.java

public static void main(String[] args) {
    HiveServer2 hi = null;/*w ww .jav  a 2  s .c  om*/

    AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring/application-context.xml",
            HiveApp.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();

    HiveTemplate template = context.getBean(HiveTemplate.class);
    List<String> tables = template.query("show tables;");
    for (String tablName : tables) {
        log.info(tablName);
    }

    PasswordProcessRepository repository = context.getBean(HivePasswordProcessRepository.class);
    repository.processPasswordFile("/etc/passwd");
    log.info("Count of password entries = " + repository.count());
    context.close();
    log.info("Hive Application Completed");
}

From source file:com.oreilly.springdata.hadoop.hive.HiveAppWithApacheLogs.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/hive-apache-log-context.xml", HiveAppWithApacheLogs.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();/*from w w  w.  j av  a2 s .  c o  m*/

    HiveRunner runner = context.getBean(HiveRunner.class);
    runner.call();

    /*
    JdbcPasswordRepository repo = context.getBean(JdbcPasswordRepository.class);      
    repo.processPasswordFile("password-analysis.hql");   
    log.info("Count of password entrires = " + repo.count());
    */
    /*
    AnalysisService analysis = context.getBean(AnalysisService.class);
    analysis.performAnalysis();
    */
    /*
    System.out.println("hit enter to run again");
    Scanner scanIn = new Scanner(System.in);
     scanIn.nextLine();
     */

}

From source file:pkg.MainApp.java

public static void main(String[] args) {
    // create application context and load beans configuration file 
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    // get required bean.
    // getBean() uses bean ID to return a generic object
    // which finally can be casted to actual object
    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
    obj.getMessage();/* w w w .  j  ava  2s .com*/

    // use the singleton scope for stateless beans
    HelloWorld ojbSingleton1 = (HelloWorld) context.getBean("helloSingleton");
    ojbSingleton1.setMessage("I'm Singleton");
    ojbSingleton1.getMessage();
    // output: Your Message : I'm Singleton

    HelloWorld ojbSingleton2 = (HelloWorld) context.getBean("helloSingleton");
    ojbSingleton2.getMessage();
    // output: Your Message : I'm Singleton

    // use the prototype scope for all state-full beans
    HelloWorld objPrototype1 = (HelloWorld) context.getBean("helloWorld");
    objPrototype1.setMessage("I'm Prototype");
    objPrototype1.getMessage();
    // output: Your Message : I'm Prototype

    HelloWorld objPrototype2 = (HelloWorld) context.getBean("helloWorld");
    objPrototype2.getMessage();
    // output: null

    // register a shutdown hook method to ensure a graceful shutdown 
    // and calls the relevant destroy methods
    context.registerShutdownHook();

    // execute order:
    // postProcessBeforeInitialization
    // init
    // postProcessAfterInitialization
    // bean.getMessage
    // destroy
}

From source file:com.osc.edu.chapter1.Starter.java

public static void main(String[] args) {
    logger.debug("Initializing Spring context.");

    AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "spring/application-context.xml" });

    logger.debug("Spring context initialized.");

    //Message message = (Message)applicationContext.getBean("message");
    Message message = applicationContext.getBean(Message.class);

    logger.debug("[Title] : {}", message.getTitle());
    logger.debug("[Message] : {}", message.getMessage());

    applicationContext.close();/*  w  ww  .j  a va  2 s .  c  om*/
}

From source file:com.st.si.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from   w  w w. ja  v a  2s.  com
 */
public static void main(final String... args) {

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();
    DefaultSftpSessionFactory sftpSessionFactory = context.getBean(DefaultSftpSessionFactory.class);

    SftpSession session = sftpSessionFactory.getSession();
    final DirectChannel requestChannel = (DirectChannel) context.getBean("inboundMGetRecursive");
    //final PollableChannel replyChannel = (PollableChannel) context.getBean("output");

    try {
        String dir = "/HVAC - Files For Testing/";
        requestChannel.send(new GenericMessage<Object>(dir + "*"));
        /*if (!session.exists(sftpConfiguration.getOtherRemoteDirectory())) {
           throw new FileNotFoundException("Remote directory does not exists... Continuing");
        }*/

        rename(session, dir);

        dir = "/HPwES - Files For Testing/";
        requestChannel.send(new GenericMessage<Object>(dir + "*"));
        rename(session, dir);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    /*final DirectChannel requestChannel = (DirectChannel) context.getBean("inboundMGetRecursive");
    final PollableChannel replyChannel = (PollableChannel) context.getBean("output");
            
            
    String dir = "/HVAC - Files For Testing/";
    requestChannel.send(new GenericMessage<Object>(dir + "*"));
    Message<?> result = replyChannel.receive(1000);
            
    List<File> localFiles = (List<File>) result.getPayload();
            
    for (File file : localFiles) {
       System.out.println(file.getName());
    }*/

    System.exit(0);

}