From 9fc9523ce34546a49582a6dea66e1e8c26a02ac7 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 1 May 2014 09:06:03 -0400 Subject: [PATCH] CLI Integration Sample Shutdown Fixes gh-761 Also add some sugar to the println so that it stands out a little against the logging. --- spring-boot-cli/samples/integration.groovy | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-boot-cli/samples/integration.groovy b/spring-boot-cli/samples/integration.groovy index 817e17e64b8..a914bdf52a6 100644 --- a/spring-boot-cli/samples/integration.groovy +++ b/spring-boot-cli/samples/integration.groovy @@ -4,6 +4,9 @@ package org.test @EnableIntegration class SpringIntegrationExample implements CommandLineRunner { + @Autowired + private ApplicationContext context; + @Bean DirectChannel input() { new DirectChannel(); @@ -11,7 +14,17 @@ class SpringIntegrationExample implements CommandLineRunner { @Override void run(String... args) { - println new MessagingTemplate(input()).convertSendAndReceive("World", String) + println() + println '>>>> ' + new MessagingTemplate(input()).convertSendAndReceive("World", String) + ' <<<<' + println() + /* + * Since this is a simple application that we want to exit right away, + * close the context. For an active integration application, with pollers + * etc, you can either suspend the main thread here (e.g. with System.in.read()), + * or exit the run() method without closing he context, and stop the + * application later using some other technique (kill, JMX etc). + */ + context.close() } }