我有以下代码:Spring应用程序不会退出
public class TutorialSender {
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("rabbit-sender-context.xml");//loading beans
AmqpTemplate aTemplate = (AmqpTemplate) context.getBean("tutorialTemplate");// getting a reference to the sender bean
JSONObject obj = new JSONObject();
obj.put("messageType", "ETL:ToFile");
for (int i = 0; i < 100; i++) {
aTemplate.convertAndSend("ETLQueue",obj.toString());// send
// aTemplate.convertAndSend("Message # " + i + " on " + new Date());// send
}
System.out.println("send is done");
}
}
然后我运行应用程序,它运行到最后一行,我可以看到“发送完成”被打印出来,但应用程序没有按退出。是因为春天阻止它退出吗?我该如何退出?
更新:我们不能使用context.close()
直接既然有如此接近()函数,而不是需要使用以下
((ClassPathXmlApplicationContext) context).close();
而不是铸造,只是为你的'上下文'变量使用更具体的类型。 – chrylis 2014-11-08 07:41:35