final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:META-INF/spring/integration/spring-integration-sample2-context.xml");
context.registerShutdownHook();
context.refresh();
final CoffeeService service = context.getBean(CoffeeService.class);
final String message = "\n\n" +
"* Please enter 'list' and press <enter> to get a list of coffees.\n" +
"* Enter a coffee id, e.g. '1' and press <enter> to get a description.\n" +
"* Please press 'q + Enter' to quit the application.\n";
System.out.println(message);
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");
}