簡體   English   中英

秋千和彈簧

[英]Swing and Spring

我正在使用spring創建一個MVC desktop application

在主要方法中,我創建了AnnotationConfigApplicationContext

創建MainForm的控制器后,它將顯示主窗體視圖(JFrame)。

我將MainFormView設置為setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

// when the MainFormController is created, it shows the MainForm JFrame.
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("...");
try {
   // WAIT FOR MAINFORM CLOSE! How?
} finally {
   ctx.close();       
}

我的問題是:

我需要關閉AnnotationConfigApplicationContext嗎? 如果是,我該怎么做,等待MainForm關閉,然后關閉應用程序上下文?

只需注冊關閉掛鈎,它將在退出時很好地關閉。

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("...");
ctx.registerShutdownHook();

然后就沒有直接的ctx.close()了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM