我有一個Spring Boot應用程序,並且使用Spring AMQP。我需要實現ApplicationContext
關閉事件我自己的自定義邏輯,所以我在bean來實現DisposableBean
,像這樣:如何在Spring AMQP bean後強制bean處理
public class ShutdownHandler implements DisposableBean {
@Override
public void destroy() throws Exception {
// I need access message listener containers here
}
}
的問題是,當我運行我的代碼,所有的AMQP豆已經被關閉,我收到以下異常:
The ApplicationContext is closed and the ConnectionFactory can no longer create connections.
主要是,我需要一些隊列移動郵件給他人,爲了恢復處理時,我的應用程序再次啓動。 我發現問題歸因於AbstractMessageListenerContainer
的階段設置爲Integer.MAX_VALUE,因此它將作爲第一個應用程序上下文bean之一處理。 我想什麼(沒有成功):
@DependsOn("listenerContainer")
註釋- 實施
SmartLifecycle
和設置階段Integer.MAX_VALUE的
你知道其他方式在應用程序上下文停機狀態,迫使秩序和有訪問Spring AMQP bean?