List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:com.apress.prospringintegration.endpoints.eventdrivenconsumer.Main.java
public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "event-driven-consumer.xml"); applicationContext.start();// www . jav a 2 s . c o m ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class); DirectChannel channel = applicationContext.getBean("ticketChannel", DirectChannel.class); EventDrivenConsumer eventDrivenConsumer = new EventDrivenConsumer(channel, ticketMessageHandler); eventDrivenConsumer.start(); List<Ticket> tickets = ticketGenerator.createTickets(); int count = 0; while (count++ < 5) { for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } } }
From source file:nats.client.spring.NatsApplicationEventTest.java
public static void main(String[] args) throws Exception { // TODO Make automated test that starts a NATS server and then runs test. // Nats server must running before running this test. final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "natsApplicationEventContext.xml"); try {//from ww w . j a v a2 s . c o m final Nats nats = context.getBean(Nats.class); Assert.assertNotNull(nats); final boolean invokedConnected = context.getBean("connected", ConnectListener.class).invoked.await(2, TimeUnit.SECONDS); Assert.assertTrue(invokedConnected, "The connected application event was never published."); final boolean invokedReady = context.getBean("ready", ReadyListener.class).invoked.await(2, TimeUnit.SECONDS); Assert.assertTrue(invokedReady, "The server ready application event was never published."); nats.close(); final boolean invokedClosed = context.getBean("closed", ClosedListener.class).invoked.await(2, TimeUnit.SECONDS); Assert.assertTrue(invokedClosed, "The closed application event was never published."); } finally { context.close(); } }
From source file:gov.nih.nci.cabig.caaers.tools.ExcelImporter.java
public static void main(String[] args) { try {/*from w ww. j ava2 s. c o m*/ if (StringUtils.isBlank(args[0])) { System.out.println("Error:: Excel file not provided"); System.out.println("Useage:: ant importexcel -Dfilelocation=<absolutefilepath>"); return; } checkDsPropertiesExistence(); String identity = "ANONYMOUS"; String info = "importStudy"; DataAuditInfo.setLocal(new DataAuditInfo(identity, "localhost", new Date(), info)); File inputFile = new File(args[0]); ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( getConfigLocations()); ExcelProcessor excelProcessor = (ExcelProcessor) applicationContext.getBean("excelProcessor"); excelProcessor.processExcel(inputFile); } catch (Exception ex) { System.out.println("\n Error occured: "); ex.printStackTrace(); } }
From source file:com.dinstone.jrpc.NamespaceHandlerTest.java
public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "application-context-sample.xml"); HelloService service = (HelloService) applicationContext.getBean("rhsv1"); try {/*from w w w. j a v a 2s. co m*/ testHot(service); } catch (Exception e) { e.printStackTrace(); } try { testSend1k(service); } catch (Exception e) { e.printStackTrace(); } try { System.in.read(); } catch (IOException e) { } applicationContext.close(); }
From source file:com.alibaba.dubbo.examples.validation.ValidationConsumer.java
public static void main(String[] args) throws Exception { String config = ValidationConsumer.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/* w w w . j ava 2 s . c o m*/ ValidationService validationService = (ValidationService) context.getBean("validationService"); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(50); parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); System.out.println("Validation Save OK"); // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); System.err.println("Validation Save ERROR"); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } // Delete OK validationService.delete(2, "abc"); System.out.println("Validation Delete OK"); // Delete Error try { validationService.delete(0, "abc"); System.err.println("Validation Delete ERROR"); } catch (RpcException e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println(violations); } }
From source file:com.github.liyp.dubbo.consumer.Consumer.java
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "com/github/liyp/dubbo/consumer/consumer.xml" }); context.start();//from w w w .jav a2 s . com NotifyImpl notify = (NotifyImpl) context.getBean("callback"); HelloService service = (HelloService) context.getBean("service"); System.out.println("dubbo consumer running..."); int i = 0; while (true) { String res = service.sayHello(new HelloBean(i, "lee")); // service.sayHello(i); System.out.println(ai.incrementAndGet()); if (ai.get() >= limit) { locked = true; cdl = new CountDownLatch(limit); cdl.await(); locked = false; } // Thread.sleep(1000); i++; } }
From source file:com.manning.siia.soap.SoapTripTestClient.java
public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "soap-client-applicationContext.xml", SoapTripTestClient.class); WebServiceOperations webServiceOperations = (WebServiceOperations) ctx.getBean(WebServiceOperations.class); LegQuoteCommand command = new LegQuoteCommand(builder.buildTestLeg()); Object result = webServiceOperations.marshalSendAndReceive(command); logger.info("result" + result); System.out.println(result);//from ww w . j a va 2s . c o m }
From source file:org.opencredo.demos.twityourl.TwitYourl.java
public static void main(String[] args) throws IOException, TwitterException, InterruptedException { TwitterStreamConfiguration config = parseCommandLine(args); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configFiles, TwitYourl.class); TwitterStreamInboundChannelAdapter twitterFeed = (TwitterStreamInboundChannelAdapter) context .getBean("twitterStreamFeed"); twitterFeed.setTwitterStreamConfiguration(config); Thread.sleep(10000);//from w w w . ja v a 2s . c om }
From source file:tetrad.rrd.graph.AggregationTest.java
/** * @param args//from www.j av a2 s.c o m */ public static void main(String[] args) { String[] configLocations = new String[] { "applicationContext_test.xml" }; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocations); AggregationTest aggregationTest = (AggregationTest) context.getBean("aggregationTest"); CommonDto dto = new CommonDto(); dto.setDeviceCode(1); dto.setDsname("connections_current"); dto.setCount(900); dto.setCollname("serverStatus"); Object object = aggregationTest.execute(dto); if (object != null) { List result = (List) object; for (Object obj : result) { System.out.println(obj); } } }
From source file:validation.ValidationConsumer.java
public static void main(String[] args) throws Exception { String config = ValidationConsumer.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/*from w w w . j a v a 2 s . c o m*/ ValidationService validationService = (ValidationService) context.getBean("validationService"); // ValidationService validationService=new ValidationServiceImpl(); // Save OK ValidationParameter parameter = new ValidationParameter(); parameter.setName("liangfei"); parameter.setEmail("liangfei@liang.fei"); parameter.setAge(1011111); parameter.setLoginDate(new Date(System.currentTimeMillis() + 1000000)); parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000)); validationService.save(parameter); System.out.println("Validation Save OK"); // Save Error try { parameter = new ValidationParameter(); validationService.save(parameter); System.err.println("Validation Save ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } // Delete OK validationService.delete(2, "abc"); System.out.println("Validation Delete OK"); // Delete Error try { validationService.delete(0, "abc"); System.err.println("Validation Delete ERROR"); } catch (Exception e) { ConstraintViolationException ve = (ConstraintViolationException) e.getCause(); Set<ConstraintViolation<?>> violations = ve.getConstraintViolations(); System.out.println("---save-" + violations); } }