List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType) throws BeansException
From source file:com.oreilly.springdata.hadoop.pig.PigAppWithRepository.java
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/pig-context-password-repository.xml", PigAppWithRepository.class); log.info("Pig Application Running"); context.registerShutdownHook();/*w w w .j a v a2s .c o m*/ String outputDir = "/data/password-repo/output"; FsShell fsShell = context.getBean(FsShell.class); if (fsShell.test(outputDir)) { fsShell.rmr(outputDir); } PasswordRepository repo = context.getBean(PigPasswordRepository.class); repo.processPasswordFile("/data/passwd/input"); /* Collection<String> files = new ArrayList<String>(); files.add("/data/passwd/input"); files.add("/data/passwd/input2"); repo.processPasswordFiles(files); */ }
From source file:com.harpatec.examples.app.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w w w .j a v a 2 s.c o m*/ */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final BeanValidationService service = context.getBean(BeanValidationService.class); // // Validate a Person bean that will pass // Person person = new Person(); person.setFirstName("Davey"); person.setLastName("Jones"); validateObject(service, person); // // Validate a Person bean that will fail // person = new Person(); person.setFirstName(""); person.setLastName("Jones"); validateObject(service, person); // // Validate an Address bean that will pass // Address address = new Address(); address.setStreetNumber("12345"); address.setStreetName("Main St."); address.setCity("Anytown"); address.setState("CA"); address.setZipCode("70808"); validateObject(service, address); // // Validate an Address bean that will fail // address = new Address(); address.setStreetNumber(null); address.setStreetName(""); address.setCity("Anytown"); address.setState("CA2"); address.setZipCode("70808123123"); validateObject(service, address); System.exit(0); }
From source file:com.hsbc.srbp.commonMsg.test.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w ww . ja v a 2 s. c o m*/ */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "jdbcInboundApplicationContext.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final CommonMessageService commonMessageService = context.getBean(CommonMessageService.class); System.out.println("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { createMessageDetails(scanner, commonMessageService, context); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } System.out.println("Exiting application...."); System.exit(0); }
From source file:com.harpatec.examples.Main.java
/** * Load the Spring Integration Application Context * //from w w w. j a va 2s . c o m * @param args - command line arguments * @throws InterruptedException * @throws IOException * @throws JsonMappingException * @throws JsonGenerationException */ public static void main(final String... args) throws InterruptedException, JsonGenerationException, JsonMappingException, IOException { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); LOGGER.debug("Dropping the collection of MessageRecords"); MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class); mongoTemplate.dropCollection(MessageRecord.class); mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("key", Order.ASCENDING).unique()); mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("completionTime", Order.ASCENDING)); RabbitTemplate inboundTemplate = (RabbitTemplate) context.getBean("amqpTemplateInbound"); Map<String, Object> messageMap = new HashMap<String, Object>(); messageMap.put("count", "4"); LOGGER.debug("Submitting first message which should pass DuplicateMessageFilter ok."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); LOGGER.debug("Submitting a duplicate message which should get caught by the DuplicateMessageFilter."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); messageMap.put("count", "0"); LOGGER.debug("Submitting a message which will not go all the way through the message flow."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); messageMap.put("count", "1"); messageMap.put("fail", "true"); LOGGER.debug("Submitting a message which should signal that an Exception should be thrown."); submitMessage(inboundTemplate, messageMap); Thread.sleep(6 * 60 * 1000); System.exit(0); }
From source file:com.lv.tica.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*ww w. j ava2s .c o m*/ */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration!!! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:in.datashow.zla.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w ww .j a v a 2s. c o m */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:com.cjtotten.example.si.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w . ja va 2s .c om */ public static void main(final String... args) { if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); } final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); } System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } System.exit(0); }
From source file:com.hillert.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w w w. ja v a 2 s. c o m*/ */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:com.somnus.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments// w ww .j a v a 2 s.c o m */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getPropertyPath().toString()); LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); LOGGER.info("Method Validation: {}", violation.getMessage()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:samples.ConsumerApplication.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); context.registerShutdownHook();/*ww w . jav a 2s .c o m*/ boolean sync = true; if (args != null && args.length > 0) { sync = Boolean.valueOf(args[0]); } if (sync == true) { //Example of a sync consumer with Spring JMS SpringJmsConsumer consumer = (SpringJmsConsumer) context.getBean("springJmsConsumer"); consumer.run(); ((org.springframework.jms.connection.CachingConnectionFactory) context.getBean("connectionFactory")) .resetConnection(); } else { //Example of an async consumer with Spring JMS (autoStartup is normally set to true) AbstractJmsListeningContainer listenerContainer = (AbstractJmsListeningContainer) context .getBean("listenerContainer"); listenerContainer.start(); } }