我有以下代碼: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