List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType) throws BeansException
From source file:org.springframework.integration.samples.advice.FileTransferRenameAfterFailureDemo.java
public static void main(String[] args) throws Exception { 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/expression-advice-context.xml"); context.registerShutdownHook();/*from w w w . j a va2 s . c om*/ @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class); SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class); when(sessionFactory.getSession()).thenThrow(new RuntimeException("Force Failure")); fileInbound.start(); LOGGER.info("\n=========================================================" + "\n " + "\n This is the Expression Advice Sample - " + "\n " + "\n Press 'Enter' to terminate. " + "\n " + "\n Place a file in ${java.io.tmpdir}/adviceDemo ending " + "\n with .txt " + "\n The demo simulates a file transfer failure followed " + "\n by the Advice renaming the file; the result of the " + "\n rename is logged. " + "\n " + "\n========================================================="); System.in.read(); System.exit(0); }
From source file:org.springframework.integration.samples.cafe.demo.ControlBusMain.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/cafeDemo-control-bus.xml"); WaiterMonitor waiterMonitor = (WaiterMonitor) context.getBean("waiterMonitor"); int totalDeliveries = 0; while (totalDeliveries <= 3) { try {//from w ww . j ava 2 s.c om Thread.sleep(1000); } catch (InterruptedException e) { logger.error("Interrupted", e); } totalDeliveries = (Integer) waiterMonitor.sendControlScript("waiter.totalDeliveries"); logger.info("Total cafe deliveries: " + totalDeliveries); if (totalDeliveries > 3) { logger.info("stopping orders..."); waiterMonitor.sendControlScript("cafe.stop()"); logger.info("orders stopped"); } } context.close(); System.exit(0); }
From source file:org.springframework.integration.samples.enricher.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w . j a v a2s . co m */ public static void main(final String... args) { LOGGER.info(LINE_SEPARATOR + EMPTY_LINE + "\n Welcome to Spring Integration! " + EMPTY_LINE + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + EMPTY_LINE + LINE_SEPARATOR); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final UserService service = context.getBean(UserService.class); LOGGER.info(LINE_SEPARATOR + EMPTY_LINE + "\n Please press 'q + Enter' to quit the application. " + EMPTY_LINE + LINE_SEPARATOR + EMPTY_LINE + "\n This example illustrates the usage of the Content Enricher. " + EMPTY_LINE + "\n Usage: Please enter 1 or 2 or 3 + Enter " + EMPTY_LINE + "\n 3 different message flows are triggered. For sample 1+2 a " + "\n user object containing only the username is passed in. " + "\n For sample 3 a Map with the 'username' key is passed in and enriched " + "\n with the user object using the 'user' key. " + EMPTY_LINE + "\n 1: In the Enricher, pass the full User object to the request channel. " + "\n 2: In the Enricher, pass only the username to the request channel. " + "\n 3: In the Enricher, pass only the username to the request channel. " + EMPTY_LINE + LINE_SEPARATOR); while (!scanner.hasNext("q")) { final String input = scanner.nextLine(); User user = new User("foo", null, null); if ("1".equals(input)) { final User fullUser = service.findUser(user); printUserInformation(fullUser); } else if ("2".equals(input)) { final User fullUser = service.findUserByUsername(user); printUserInformation(fullUser); } else if ("3".equals(input)) { final Map<String, Object> userData = new HashMap<String, Object>(); userData.put("username", "foo_map"); final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData); final User fullUser = (User) enrichedUserData.get("user"); printUserInformation(fullUser); } else { LOGGER.info("\n\n Please enter '1', '2', or '3' <enter>:\n\n"); } } LOGGER.info("\n\nExiting application...bye."); scanner.close(); context.close(); }
From source file:org.springframework.integration.samples.jdbc.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from www.ja va 2 s .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 PersonService personService = context.getBean(PersonService.class); LOGGER.info("\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. Find person details"); System.out.println("\t2. Create a new person 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())) { getPersonDetails(scanner, personService); } else if ("2".equals(input.trim())) { createPersonDetails(scanner, personService); } 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. Find person details"); System.out.println("\t2. Create a new person detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } LOGGER.info("Exiting application...bye."); context.close(); }
From source file:org.springframework.integration.samples.poller.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments// w w w.j a v a2 s. c om */ public static void main(final String... args) { LOGGER.info("\n==========================================================" + "\n " + "\n Welcome to the Spring Integration Dynamic Poller Sample! " + "\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 DynamicPeriodicTrigger trigger = context.getBean(DynamicPeriodicTrigger.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.print("Please enter a non-negative numeric value and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { int triggerPeriod = Integer.valueOf(input); System.out.println(String.format("Setting trigger period to '%s' ms", triggerPeriod)); trigger.setPeriod(triggerPeriod); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a non-negative numeric value and press <enter>: "); } LOGGER.info("Exiting application...bye."); scanner.close(); context.close(); }
From source file:org.springframework.integration.samples.splitteraggregator.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w ww .ja va 2 s .com */ 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 SearchRequestor searchRequestor = context.getBean(SearchRequestor.class); final SearchA searchA = context.getBean(SearchA.class); final SearchB searchB = context.getBean(SearchB.class); final Scanner scanner = new Scanner(System.in); System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Submit 2 search queries, 2 results returned."); System.out.println("\t2. Submit 2 search queries, 1 search query takes too long, 1 result returned."); System.out.println("\t3. Submit 2 search queries, 2 search queries take too long, 0 results returned."); System.out.println("\tq. Quit the application"); System.out.print("Enter your choice: "); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { searchA.setExecutionTime(1000L); searchB.setExecutionTime(1000L); final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria()); System.out.println("Number of Search Results: " + result.getResults().size()); } else if ("2".equals(input.trim())) { searchA.setExecutionTime(6000L); searchB.setExecutionTime(1000L); final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria()); System.out.println("Number of Search Results: " + result.getResults().size()); } else if ("3".equals(input.trim())) { searchA.setExecutionTime(6000L); searchB.setExecutionTime(6000L); final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria()); System.out.println("Result is null: " + (result == null)); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } } System.out.println("Exiting application...bye."); scanner.close(); context.close(); }
From source file:org.springframework.integration.samples.storedprocedure.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from ww w . j av a 2 s . c o m*/ */ public static void main(final String... args) { LOGGER.info(LINE + LINE + "\n Welcome to Spring Integration Coffee Database! " + NEWLINE + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + NEWLINE + LINE); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final CoffeeService service = context.getBean(CoffeeService.class); LOGGER.info(LINE + NEWLINE + "\n Please press 'q + Enter' to quit the application." + NEWLINE + LINE); System.out.print("Please enter 'list' and press <enter> to get a list of coffees."); System.out.print("Enter a coffee id, e.g. '1' and press <enter> to get a description.\n\n"); while (!scanner.hasNext("q")) { String input = scanner.nextLine(); if ("list".equalsIgnoreCase(input)) { List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages(); for (CoffeeBeverage coffeeBeverage : coffeeBeverages) { System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName())); } } else { System.out.println("Retrieving coffee information..."); String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input)); System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription)); System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n"); } } LOGGER.info("Exiting application...bye."); scanner.close(); context.close(); }
From source file:org.springframework.samples.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 ww.ja v a 2s . co m HiveTemplate template = context.getBean(HiveTemplate.class); template.query("show tables;"); PasswordRepository repository = context.getBean(HiveTemplatePasswordRepository.class); repository.processPasswordFile("/etc/passwd"); log.info("Count of password entries = " + repository.count()); }
From source file:org.springframework.samples.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();// www.j av a2 s . c om HiveRunner runner = context.getBean(HiveRunner.class); runner.call(); }
From source file:org.springframework.samples.hadoop.hive.HiveBatchApp.java
public static void main(String[] args) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { System.out.println("TEST"); AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/META-INF/spring/*-context.xml"); log.info("Batch Tweet Influencers Hive Job Running"); context.registerShutdownHook();/* w w w . j a v a 2 s .c om*/ JobLauncher jobLauncher = context.getBean(JobLauncher.class); Job job = context.getBean(Job.class); jobLauncher.run(job, new JobParameters()); }