List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.mzd.shap.spring.cli.Index.java
public static void main(String[] args) { if (args.length != 0) { System.out.println(USAGE_MSG); System.exit(1);/*from ww w. ja v a2 s . c o m*/ } try { ApplicationContext ctx = new ClassPathXmlApplicationContext("datasource-context.xml", "orm-massindex-context.xml"); SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory"); Session session = sessionFactory.openSession(); System.out.println(BEGIN_MSG); LOGGER.info(BEGIN_MSG); // Index single-threaded. Appear to have problems with collections. Search.getFullTextSession(session).createIndexer().batchSizeToLoadObjects(30) .threadsForSubsequentFetching(4).threadsToLoadObjects(2).cacheMode(CacheMode.NORMAL) .optimizeOnFinish(true).startAndWait(); //LOGGER.debug(Reporting.reportQueryCacheStatistics(sessionFactory)); //LOGGER.debug(Reporting.reportSecondLevleCacheStatistics(sessionFactory)); System.out.println(FINISH_MSG); LOGGER.info(FINISH_MSG); System.exit(0); } catch (Exception ex) { System.err.println(ERROR_MSG + " [" + ex.getMessage() + "]"); LOGGER.debug(ERROR_MSG, ex); } }
From source file:tsp.TSPTestSpring.java
public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml"); ITSPAlgorithm tspBruteForce = (ITSPAlgorithm) context.getBean("tspBruteForce"); ITSPAlgorithm tspNearestNeighbor = (ITSPAlgorithm) context.getBean("tspNearestNeighbor"); ITSPAlgorithm tspRandomSelection = (ITSPAlgorithm) context.getBean("tspRandomSelection"); ITSPAlgorithm tspGeneticAlgorithm = (ITSPAlgorithm) context.getBean("tspGeneticAlgorithm"); // test//from www . ja v a 2 s. c o m ITSPAlgorithm tspGeneticAlgorithm2 = (ITSPAlgorithm) context.getBean("tspGeneticAlgorithm"); if (tspGeneticAlgorithm == tspGeneticAlgorithm2) System.out.println("[TEST] The Same instance!!!"); List<TSPPath> bestPathList; Iterator it; tspBruteForce.getGraph().printGraph(); // Brute Force // if (g.getNumVertex()>100) return; System.out.printf("The Best Routes Found By Brute Force:\n"); bestPathList = tspBruteForce.getBestPathList(3); it = bestPathList.iterator(); while (it.hasNext()) { TSPPath path = ((TSPPath) it.next()); path.printPathStartingFrom(0); } System.out.println(""); // Select the best XXX routes from a randomly generated sample pool System.out.printf("The Best Routes Found (Approximation By Random Selection and Ranking):\n"); // System.out.printf("Sample Size: %d\n", tspRandomSelection.getSampleSize()); bestPathList = tspRandomSelection.getBestPathList(3); it = bestPathList.iterator(); while (it.hasNext()) { TSPPath path = ((TSPPath) it.next()); path.printPathStartingFrom(0); } System.out.println(""); // Select the best XXX routes by Nearest Neighbor System.out.printf("The Best Routes Found (Approximation By Nearest Neighbor):\n"); bestPathList = tspNearestNeighbor.getBestPathList(3); it = bestPathList.iterator(); while (it.hasNext()) { TSPPath path = ((TSPPath) it.next()); path.printPathStartingFrom(0); } System.out.println(""); // Select the best XXX routes by Genetic Algorithm System.out.printf("The Best Routes Found (Approximation By Genetic Algorithm):\n"); // System.out.printf("Population Size: %d\n", tspGeneticAlgorithm.getPopSize()); bestPathList = tspGeneticAlgorithm.getBestPathList(3); it = bestPathList.iterator(); while (it.hasNext()) { TSPPath path = ((TSPPath) it.next()); path.printPathStartingFrom(0); } System.out.println(""); }
From source file:com.github.liyp.rabbitmq.demo.Main.java
public static void main(String[] args) throws IOException, InterruptedException { // start spring context @SuppressWarnings({ "resource" }) ApplicationContext context = new ClassPathXmlApplicationContext( "com/github/liyp/rabbitmq/demo/applicationContext.xml"); RabbitTemplate rabbitTemplate = (RabbitTemplate) context.getBean("rabbitTemplate"); for (int i = 0; i < 200; i++) { rabbitTemplate.convertAndSend("queue_one", "test queue 1 " + i); rabbitTemplate.convertAndSend("queue_two", new MsgBean("test queue 2 " + i)); }/*from ww w . j ava2 s . com*/ Thread.sleep(5000); ThreadPoolTaskExecutor threadExe = (ThreadPoolTaskExecutor) context.getBean("taskExecutor"); System.out.println(threadExe.getActiveCount()); System.out.println(threadExe.getCorePoolSize()); System.out.println(threadExe.getMaxPoolSize()); System.out.println(threadExe.getPoolSize()); System.out.println(threadExe.getThreadPoolExecutor().getCorePoolSize()); // System.out.println("rsv: " + // rabbitTemplate.receiveAndConvert("queue_two")); }
From source file:org.ala.lucene.CreateSearchIndex.java
public static void main(String[] args) throws Exception { ApplicationContext context = SpringUtils.getContext(); if (args.length == 0 || "-geo".equals(args[0])) { logger.info("Loading geo regions into search indexes...."); GeoRegionDao grDao = (GeoRegionDao) context.getBean(GeoRegionDao.class); grDao.createIndex();//from www. jav a 2 s . c o m logger.info("Finished loading geo regions into search indexes."); } if (args.length == 0 || "-taxa".equals(args[0])) { logger.info("Creating species indexes..."); TaxonConceptDao tcDao = (TaxonConceptDao) context.getBean(TaxonConceptDao.class); boolean replace = args.length > 1 && "-replace".equals(args[1]); String start = ""; if (args.length > 0 && !args[0].startsWith("-")) start = args[0]; if (args.length > 1 && !args[1].startsWith("-")) start = args[1]; if (args.length > 2 && !args[2].startsWith("-")) start = args[2]; tcDao.createIndex(start, !replace); logger.info("Finished creating species indexes."); } System.exit(0); }
From source file:com.nicodemo.view.MainForm.java
/** * @param args the command line arguments *//*from w w w.j a v a 2 s . c o m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> ApplicationContext context = new ClassPathXmlApplicationContext("main/resources/beans.xml"); context.getBean(DevEntitiesInitializer.class).Initialize(); /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainForm(context).setVisible(true); } }); }
From source file:com.mir00r.Main.java
public static void main(String[] args) { // XML based configuraiotn // ApplicationContext context = new ClassPathXmlApplicationContext("com/mir00r/beans.xml"); ///* w ww. j a v a 2 s . c o m*/ // Hello hel = (Hello) context.getBean("hello"); // // hel.setMessage("Hello Spring World"); // System.out.println(hel.getMessage()); // // // Annotation based configuration example // ApplicationContext context2 = new AnnotationConfigApplicationContext(Hello_Configuration_MB.class); // // Hello hel2 = (Hello) context2.getBean("hello"); // // hel2.setMessage("Hello Spring World 2 -----"); // System.out.println(hel2.getMessage()); // Dependency Injection Example using Constructor // ApplicationContext ac = new ClassPathXmlApplicationContext("com/mir00r/beans.xml"); // Employee em = (Employee) ac.getBean("emp"); // em.show(); // Bean Lifecycle Example how bean init and destroy // AbstractApplicationContext aac = new ClassPathXmlApplicationContext("com/mir00r/beans.xml"); // aac.registerShutdownHook(); // forcefully Shutdown AbstractApplicationContext class // // Hello hel = (Hello) aac.getBean("hello"); // // hel.setMessage("Hello Spring World"); // System.out.println(hel.getMessage()); ApplicationContext ac = new ClassPathXmlApplicationContext("com/mir00r/beans.xml"); //ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("com/mir00r/beans.xml"); Employee em = (Employee) ac.getBean("emp2"); em.show(); }
From source file:org.ala.lucene.CreateWordPressIndex.java
public static void main(String[] args) throws Exception { // Spring config file locations String[] locations = { "classpath*:spring.xml" }; // initialise Spring ApplicationContext ApplicationContext context = new ClassPathXmlApplicationContext(locations); CreateWordPressIndex cwpi = (CreateWordPressIndex) context.getBean(CreateWordPressIndex.class); cwpi.loadWordpress();//from w w w .jav a 2 s . c om System.exit(0); }
From source file:org.manalith.ircbot.ManalithBot.java
public static void main(String[] args) throws Exception { // ? /*from w w w . ja v a2s.c o m*/ if (!Charset.defaultCharset().toString().equals("UTF-8")) { System.out.println("-Dfile.encoding=UTF-8 ."); return; } // ? Options options = new Options(); options.addOption("c", true, "config file"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String configFile = cmd.getOptionValue("c", "config.xml"); // SSL/HTTPS UrlUtils.setTrustAllHosts(); // ApplicationContext context = new FileSystemXmlApplicationContext(configFile); AppContextUtils.setApplicationContext(context); // ? ManalithBot bot = context.getBean(ManalithBot.class); bot.startBot(); }
From source file:com.SCI.centraltoko.Main.java
@SuppressWarnings("Convert2Lambda") public static void main(String[] args) { // TODO code application logic here // Memasang LookAndFeel try {// www. j a va2 s. co m for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } // Membuat tread try { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "SpringXMLConfig.xml"); masterService = (MasterService) applicationContext.getBean("masterService"); transaksiService = (TransaksiSevice) applicationContext.getBean("transaksiSevice"); laporan = (Laporan) applicationContext.getBean("laporan"); mainFrame = new MainFrame(); mainFrame.setVisible(true); } }); } catch (Exception ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:core.App.java
public static void main(String[] args) { // For XML//from ww w. j a v a 2 s. co m //ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml"); // For Annotation ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class); MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate"); //Student user = new Student("3", "federico", "solterman", "26-10-1990"); // save //mongoOperation.save(user); // now user object got the created id. // System.out.println("1. user : " + user); // query to search user // Query searchUserQuery = new Query(Criteria.where("first_name").is("federico")) { //}; // find the saved user again. //Student savedUser = mongoOperation.findOne(searchUserQuery, Student.class); // System.out.println("2. find - savedUser : " + savedUser); //This method Fetch all students whose notes in a specific course were greater than 4 BasicQuery query = new BasicQuery( "{ $and: [{ note_1: {$gt:4 }, note_2: {$gt:4}, note_3: {$gt:4},note_final:{$gt:4 } } ] }"); List<StudentXCourseXNote> stu = mongoOperation.find(query, StudentXCourseXNote.class); StudentXCourseXNote aux; for (int i = 0; i < stu.size(); i++) { aux = stu.get(i); BasicQuery query1 = new BasicQuery("{id_registration:" + " \"" + aux.getId_student() + "\"}"); Student student = mongoOperation.findOne(query1, Student.class); System.out.println(student.toString()); } //Fetch all courses ordered by name for a given teacher BasicQuery query2 = new BasicQuery("{ last_name:\"Sulma\" }"); Teacher teacher = mongoOperation.findOne(query2, Teacher.class); BasicQuery query3 = new BasicQuery("{ id_teacher: \"" + teacher.getId_teacher() + "\"}"); List<TeacherXCourse> list = mongoOperation.find(query3, TeacherXCourse.class); TeacherXCourse aux2; for (int j = 0; j < list.size(); j++) { aux2 = list.get(j); BasicQuery query4 = new BasicQuery("{id_course: \"" + aux2.getId_course() + "\" }"); Course course = mongoOperation.findOne(query4, Course.class); System.out.println(course.toString()); } //This method add a new fields in the collection course BasicQuery queryPoint4 = new BasicQuery("{ },{ $set: { finish: boolean } },{ multi: true }"); Update update = new Update(); update.set("{}", ""); mongoOperation.updateFirst(queryPoint4, null, Course.class); // update password /*mongoOperation.updateFirst(searchUserQuery, Update.update("password", "new password"), Student.class);*/ // find the updated user object /*Student updatedUser = mongoOperation.findOne(searchUserQuery, Student.class);*/ //System.out.println("3. updatedUser : " + updatedUser); // delete // mongoOperation.remove(searchUserQuery, Student.class); // List, it should be empty now. /* List<Student> listUser = mongoOperation.findAll(Student.class); System.out.println("4. Number of user = " + listUser.size());*/ }