簡體   English   中英

從單例bean中調用會話范圍的bean的init方法

[英]Call init-method of a session-scoped bean from a singleton bean

我有一個會話作用域的bean,它使用代理注入到單例bean中。
從單例bean中,我需要調用會話范圍的bean的某個初始化方法,該方法需要單例bean作為參數。 此外,我無法更改會話范圍的bean的源。

要詳細說明該案例:
單例bean是Service,會話作用域bean是Vaadin4Spring eventbus,為此,我需要調用方法eventBus.subscribe(this)

似乎沒有任何方法可以檢查我是否已訂閱,並且一定不能在某個eventBus實例上調用兩次。

當代理第一次鏈接到eventBus實例時,有沒有辦法告訴Spring調用eventBus.subscribe(this)

您是否不能反過來,將服務注入到事件總線中,並在this.subscribe(serviceBean)@PostConstruct注釋方法中調用this.subscribe(serviceBean) 然后,僅在構造事件總線時才調用一次。

您可以將@Lazy添加到Singleton。 您不需要代理。

暫無
暫無

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

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