![](/img/trans.png)
[英]Injecting a SessionScoped Bean inside a View Scoped bean in JSF
[英]How can I reach JSF @Singleton Bean from inside @SessionScoped Bean and vice versa?
我的目的是擁有一個@Singleton class,它在雲服務器上的整個應用程序中運行自動調度方法。 但我也有我想與之交流的@SessionScoped bean。 如果我不在用戶的網絡會話中,是否可以訪問@SessionScoped bean,反之亦然:如何使用我的@Singleton Bean 作為 session 的用戶?
謝謝和最好的問候!
您可以使用應用程序上下文在 SessionScoped Bean 中訪問 Singleton Bean 以獲取 Singleton bean 或在 SessionScoped Bean 中注入。
context.getBean(SomeSingletonClass.class)
反過來,沒有什么好辦法,你可以將會話放在 se Singleton bean 內的 WeakReference 列表中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.