List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:koper.demo.main.SendDataEventMsgDemo.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml", "kafka/context-data-producer.xml"); Order order = new Order(); order.setId(100);//from w ww.j a va 2 s. co m order.setOrderNo("order_no"); order.setCreatedTime("oroder_created_time"); OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); orderService.insertOrder(order); orderService.updateOrder(order); }
From source file:com.futuremove.cacheServer.service.impl.CarDynPropsServiceImpl.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test.xml"); CarDynPropsService service = (CarDynPropsService) context.getBean("CarDynPropsService"); CarDynProps props = new CarDynProps(); props.location = new CarLocation(); //props.vinNum = "10012"; props.state = 0;//from ww w .j a v a 2 s . c o m props.owner = ""; props.acc = 0; props.powerPercent = 1.0; props.mileage = 1.0; props.lockState = 1; String[] licenseNum_arr = { "A32145", "BS1111", "B66666", "B88888", "B86868", "NOPN11", "B0009m", "B00091", "Q7JF17", "A12345", "A12445", "A12645", "A12745", "A12845", "A12045", "A22345", "A32345", "A42345", "A52345", "A62345", "A72345", "A92345", "A02345", "A22045" }; String[] vinNum_arr = { "12345116553006992", "23456527859110284", "12345619005153690", "12345619005153691", "12345619005153692", "12345619005153693", "12345619005153694", "12345619005153695", "10012", "JYFMSODA36A201571", "JYFMSODA36A201572", "JYFMSODA36A201573", "JYFMSODA36A201574", "JYFMSODA36A201575", "JYFMSODA36A201576", "JYFMSODA36A201577", "JYFMSODA36A201578", "JYFMSODA36A201579", "JYFMSODA36A201580", "JYFMSODA36A201581", "JYFMSODA36A201582", "JYFMSODA36A201583", "JYFMSODA36A201584", "JYFMSODA36A201585" }; for (int i = 0; i < licenseNum_arr.length; i++) { props.licenseNum = licenseNum_arr[i]; props.vinNum = vinNum_arr[i]; service.insert(props); } }
From source file:com.exploringspatial.job.AcladLoaderJob.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Error: missing output directory path."); System.out.println("Usage: java AcladLoaderJob outputPath eventsCsvFileName"); }//from w w w . j a v a2 s.c o m ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml"); AcladLoaderJob acladLoaderJob = (AcladLoaderJob) applicationContext.getBean("acladLoaderJob"); try { acladLoaderJob.run(args); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:org.ala.harvester.IdentifyLifeHarvester.java
/** * @param args/*from www . java2s . c om*/ */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.print("Usage: "); System.out.print("<infosourceId>"); System.out.println(); System.out.println("infosourceId e.g. 1036"); System.exit(1); } String[] locations = { "classpath*:spring.xml" }; ApplicationContext context = new ClassPathXmlApplicationContext(locations); IdentifyLifeHarvester identifyLifeHarvester = context.getBean(IdentifyLifeHarvester.class); HashMap<String, String> connectParams = new HashMap<String, String>(); connectParams.put(SEARCH_END_POINT_ATTR_NAME, "http://www.identifylife.org:8001/Keys/Search"); connectParams.put(KEY_END_POINT_ATTR_NAME, "http://www.identifylife.org:8001/Keys"); connectParams.put(KEY_FIELD_ATTR_NAME, SEARCH_FIELD_TAXO_SCOPE); identifyLifeHarvester.setConnectionParams(connectParams); identifyLifeHarvester.setDocumentMapper(new IdentifyLifeDocumentMapper()); identifyLifeHarvester.start(Integer.parseInt(args[0]), 500); System.exit(0); }
From source file:org.ala.lucene.Autocompleter.java
public static void main(String[] args) throws Exception { // run this to re-index from the current index, shouldn't need to do // this very often //autocomplete.reIndex(FSDirectory.getDirectory("/index/live", null), "content"); Autocompleter autocomplete = new Autocompleter(); if (true) {//from w w w .j a v a2 s. c o m ApplicationContext context = SpringUtils.getContext(); TaxonConceptDao tcDao = (TaxonConceptDao) context.getBean(TaxonConceptDao.class); System.out.println("Starting re-indexing..."); System.out.println("creating scientificName index"); autocomplete.reIndex(FSDirectory.open(new File(INDEX_DIR_NAME), null), "scientificName", true); Thread.sleep(2000); System.out.println("creating commonName index"); autocomplete.reIndex(FSDirectory.open(new File(INDEX_DIR_NAME), null), "commonName", false); System.out.println("Finished re-indexing..."); } Thread.sleep(2000); String term = "rufus"; System.out.println("autocompleting: " + term + " = " + autocomplete.suggestTermsFor(term, 5)); term = "frog"; System.out.println("autocompleting: " + term + " = " + autocomplete.suggestTermsFor(term, 5)); // prints [steve, steven, stevens, stevenson, stevenage] }
From source file:org.project.ExampleApplication.java
public static void main(String[] args) throws Exception { ApplicationContext ctx = SpringApplication.run(ExampleApplication.class, args); // Showing all the beans mapped String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames);// w ww . j a v a2 s. c om for (String beanName : beanNames) { System.out.println(beanName); } Bootstrap bootstrap = (Bootstrap) ctx.getBean("bootstrap"); bootstrap.setup(); }
From source file:org.ala.report.CsvReportGenerator.java
/** * @param args//from w w w.j a va2 s .co m */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("Input File Name && Output Directory...."); System.exit(0); } ApplicationContext context = SpringUtils.getContext(); CsvReportGenerator reportGen = (CsvReportGenerator) context.getBean(CsvReportGenerator.class); reportGen.runReport(args[0], args[1]); System.exit(0); }
From source file:br.com.asisprojetos.mailreport.Main.java
public static void main(String args[]) { logger.debug("Testando debug"); if (args.length < 2) { logger.error("Erro : Numero de parametros errados."); System.exit(1);/*from w w w. j av a 2s. c o m*/ } String dataIniProc = String.format("%s 00:00:00", args[0]); String dataFimProc = String.format("%s 23:59:59", args[1]); logger.debug("Data Inicial: {} , Data Final: {}", dataIniProc, dataFimProc); String mes = String.format("%s/%s", args[0].substring(5, 7), args[0].substring(0, 4)); ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Datasource.xml"); TBRelatorioEmailDAO tbRelatorioEmailDAO = (TBRelatorioEmailDAO) context.getBean("TBRelatorioEmailDAO"); List<TBRelatorioEmail> listaRelatorioEmail = tbRelatorioEmailDAO.getAll(); for (TBRelatorioEmail tbRelatorioEmail : listaRelatorioEmail) { logger.debug(" CodContrato: {}, CodProduto: {}", tbRelatorioEmail.getCodContrato(), tbRelatorioEmail.getCodProduto()); List<String> listaEmails = tbRelatorioEmailDAO.getListaEmails(tbRelatorioEmail.getCodContrato()); if (!listaEmails.isEmpty()) { logger.debug("Lista de Emails obtida : [{}] ", listaEmails); //List<String> listaCodProduto = Arrays.asList( StringUtils.split(tbRelatorioEmail.getCodProduto(), ';') ) ; List<String> listaCodProduto = new ArrayList<String>(); listaCodProduto.add("1");//Sped Fiscal logger.debug("Gerando Relatorio Geral de Consumo por Produto..."); List<String> fileNames = new ArrayList<String>(); String fileName; BarChartDemo barChartDemo = (BarChartDemo) context.getBean("BarChartDemo"); //fileName = barChartDemo.generateBarChartGraph(tbRelatorioEmail.getCodContrato()); //fileNames.add(fileName); fileNames = barChartDemo.generateBarChartGraph2(tbRelatorioEmail.getCodContrato()); String templateFile = null; for (String codProduto : listaCodProduto) { if (codProduto.equals(Produto.SPED_FISCAL.getCodProduto())) { logger.debug("Produto Codigo : {} ", codProduto); templateFile = "index6.html"; //grafico de diagnostico fileName = barChartDemo.generateDiagnosticGraph(tbRelatorioEmail.getCodContrato(), dataIniProc, dataFimProc); fileNames.add(fileName); //grafico de auditoria recorrente fileName = barChartDemo.generateRecurrentGraph(tbRelatorioEmail.getCodContrato(), dataIniProc, dataFimProc); fileNames.add(fileName); } else { logger.debug("Produto Codigo : {} no aceito para gerar grafico ", codProduto); } logger.debug("Enviando Email.............Produto Codigo : {}", codProduto); SendEmail sendEmail = (SendEmail) context.getBean("SendEmail"); sendEmail.enviar(listaEmails.toArray(new String[listaEmails.size()]), "Relatrio Mensal de Riscos Fiscais", templateFile, fileNames, mes, tbRelatorioEmail.getCodContrato()); //sendEmail.enviar( new String[]{"leandro.prates@asisprojetos.com.br","leandro.prates@gmail.com"} , // "Relatrio Mensal de Riscos Fiscais", templateFile, fileNames, mes, tbRelatorioEmail.getCodContrato() ); } //Remover todos os arquivos png gerado para o cliente Config config = (Config) context.getBean("Config"); for (String f : fileNames) { try { File file = new File(String.format("%s/%s", config.getOutDirectory(), f)); if (file.delete()) { logger.debug("Arquivo: [{}/{}] deletado com sucesso.", config.getOutDirectory(), f); } else { logger.error("Erro ao deletar o arquivo: [{}/{}]", config.getOutDirectory(), f); } } catch (Exception ex) { logger.error("Erro ao deletar o arquivo: [{}/{}] . Message {}", config.getOutDirectory(), f, ex); } } } } }
From source file:com.mvdb.etl.actions.ExtractDBChanges.java
public static void main(String[] args) throws JSONException { ActionUtils.setUpInitFileProperty(); // boolean success = ActionUtils.markActionChainBroken("Just Testing"); // System.exit(success ? 0 : 1); ActionUtils.assertActionChainNotBroken(); ActionUtils.assertEnvironmentSetupOk(); ActionUtils.assertFileExists("~/.mvdb", "~/.mvdb missing. Existing."); ActionUtils.assertFileExists("~/.mvdb/status.InitCustomerData.complete", "300init-customer-data.sh not executed yet. Exiting"); //This check is not required as data can be modified any number of times //ActionUtils.assertFileDoesNotExist("~/.mvdb/status.ModifyCustomerData.complete", "ModifyCustomerData already done. Start with 100init.sh if required. Exiting"); ActionUtils.createMarkerFile("~/.mvdb/status.ExtractDBChanges.start", true); //String schemaDescription = "{ 'root' : [{'table' : 'orders', 'keyColumn' : 'order_id', 'updateTimeColumn' : 'update_time'}]}"; String customerName = null;//from w w w . j a va2s.c o m final CommandLineParser cmdLinePosixParser = new PosixParser(); final Options posixOptions = constructPosixOptions(); CommandLine commandLine; try { commandLine = cmdLinePosixParser.parse(posixOptions, args); if (commandLine.hasOption("customer")) { customerName = commandLine.getOptionValue("customer"); } } catch (ParseException parseException) // checked exception { System.err.println( "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage()); } if (customerName == null) { System.err.println("Could not find customerName. Aborting..."); System.exit(1); } ApplicationContext context = Top.getContext(); final OrderDAO orderDAO = (OrderDAO) context.getBean("orderDAO"); final ConfigurationDAO configurationDAO = (ConfigurationDAO) context.getBean("configurationDAO"); final GenericDAO genericDAO = (GenericDAO) context.getBean("genericDAO"); File snapshotDirectory = getSnapshotDirectory(configurationDAO, customerName); try { FileUtils.writeStringToFile(new File("/tmp/etl.extractdbchanges.directory.txt"), snapshotDirectory.getName(), false); } catch (IOException e) { e.printStackTrace(); System.exit(1); return; } long currentTime = new Date().getTime(); Configuration lastRefreshTimeConf = configurationDAO.find(customerName, "last-refresh-time"); Configuration schemaDescriptionConf = configurationDAO.find(customerName, "schema-description"); long lastRefreshTime = Long.parseLong(lastRefreshTimeConf.getValue()); OrderJsonFileConsumer orderJsonFileConsumer = new OrderJsonFileConsumer(snapshotDirectory); Map<String, ColumnMetadata> metadataMap = orderDAO.findMetadata(); //write file schema-orders.dat in snapshotDirectory genericDAO.fetchMetadata("orders", snapshotDirectory); //writes files: header-orders.dat, data-orders.dat in snapshotDirectory JSONObject json = new JSONObject(schemaDescriptionConf.getValue()); JSONArray rootArray = json.getJSONArray("root"); int length = rootArray.length(); for (int i = 0; i < length; i++) { JSONObject jsonObject = rootArray.getJSONObject(i); String table = jsonObject.getString("table"); String keyColumnName = jsonObject.getString("keyColumn"); String updateTimeColumnName = jsonObject.getString("updateTimeColumn"); System.out.println("table:" + table + ", keyColumn: " + keyColumnName + ", updateTimeColumn: " + updateTimeColumnName); genericDAO.fetchAll2(snapshotDirectory, new Timestamp(lastRefreshTime), table, keyColumnName, updateTimeColumnName); } //Unlikely failure //But Need to factor this into a separate task so that extraction does not have to be repeated. //Extraction is an expensive task. try { String sourceDirectoryAbsolutePath = snapshotDirectory.getAbsolutePath(); File sourceRelativeDirectoryPath = getRelativeSnapShotDirectory(configurationDAO, sourceDirectoryAbsolutePath); String hdfsRoot = ActionUtils.getConfigurationValue(ConfigurationKeys.GLOBAL_CUSTOMER, ConfigurationKeys.GLOBAL_HDFS_ROOT); String targetDirectoryFullPath = hdfsRoot + "/data" + sourceRelativeDirectoryPath; ActionUtils.copyLocalDirectoryToHdfsDirectory(sourceDirectoryAbsolutePath, targetDirectoryFullPath); String dirName = snapshotDirectory.getName(); ActionUtils.setConfigurationValue(customerName, ConfigurationKeys.LAST_COPY_TO_HDFS_DIRNAME, dirName); } catch (Throwable e) { e.printStackTrace(); logger.error("Objects Extracted from database. But copy of snapshot directory<" + snapshotDirectory.getAbsolutePath() + "> to hdfs <" + "" + ">failed. Fix the problem and redo extract.", e); System.exit(1); } //Unlikely failure //But Need to factor this into a separate task so that extraction does not have to be repeated. //Extraction is an expensive task. String targetZip = null; try { File targetZipDirectory = new File(snapshotDirectory.getParent(), "archives"); if (!targetZipDirectory.exists()) { boolean success = targetZipDirectory.mkdirs(); if (success == false) { logger.error("Objects copied to hdfs. But able to create archive directory <" + targetZipDirectory.getAbsolutePath() + ">. Fix the problem and redo extract."); System.exit(1); } } targetZip = new File(targetZipDirectory, snapshotDirectory.getName() + ".zip").getAbsolutePath(); ActionUtils.zipFullDirectory(snapshotDirectory.getAbsolutePath(), targetZip); } catch (Throwable e) { e.printStackTrace(); logger.error("Objects copied to hdfs. But zipping of snapshot directory<" + snapshotDirectory.getAbsolutePath() + "> to <" + targetZip + ">failed. Fix the problem and redo extract.", e); System.exit(1); } //orderDAO.findAll(new Timestamp(lastRefreshTime), orderJsonFileConsumer); Configuration updateRefreshTimeConf = new Configuration(customerName, "last-refresh-time", String.valueOf(currentTime)); configurationDAO.update(updateRefreshTimeConf, String.valueOf(lastRefreshTimeConf.getValue())); ActionUtils.createMarkerFile("~/.mvdb/status.ExtractDBChanges.complete", true); }
From source file:org.craftercms.profile.utils.AccessTokenManagerCli.java
public static void main(String... args) { ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_PATH); AccessTokenRepository repository = context.getBean(AccessTokenRepository.class); ObjectMapper objectMapper = context.getBean(ObjectMapper.class); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); PrintWriter stdOut = new PrintWriter(System.out); AccessTokenManagerCli cli = new AccessTokenManagerCli(stdIn, stdOut, repository, objectMapper); cli.run(args);// w ww.j a va2s. co m }