Tag: 弹簧集成

等待所有线程在Spring Integration中完成

我有一个自我执行的jar程序,它很大程度上依赖于Spring Integration。 我遇到的问题是程序在其他Spring bean完成之前终止 。 下面是我正在使用的代码的简化版本,如果需要,我可以提供更多代码/配置。 入口点是一个main()方法,它引导Spring并启动导入过程: public static void main(String[] args) { ctx = new ClassPathXmlApplicationContext(“flow.xml”); DataImporter importer = (DataImporter)ctx.getBean(“MyImporterBean”); try { importer.startImport(); } catch (Exception e) { e.printStackTrace(); } finally { ctx.close(); } } DataImporter包含一个简单的循环,可以将消息发送到Spring Integration网关。 这为流提供了一种主动的“推送”方法,而不是轮询数据的常用方法。 这是我的问题所在: public void startImport() throws Exception { for (Item item : items) { gatewayBean.publish(item); Thread.sleep(200); // […]