我可以将EJB Stateless Bean与CDI一起使用来维护用户会话吗? [英] Can I use EJB Stateless Bean with CDI to maintain user session?
问题描述
基于此帖子 http://www.adam-bien.com/roller/abien/entry/ejb_3_1_killed_the 我在应用程序@Named @Stateless bean中使用它与数据库进行通信(在此处注入EntityManager),并在jsf页面上显示信息.自Java EE 5以来,这非常方便.但是我有一个问题.
Based on this post http://www.adam-bien.com/roller/abien/entry/ejb_3_1_killed_the I use in my app @Named @Stateless bean for communication with a database (injecting EntityManager here) and display information on a jsf page. It's great facilitation since Java EE 5, but I have one question.
使用此类bean维护用户会话(购物车等)是否安全?我读了一本关于ejb 3.0的书,我知道许多客户都可以使用同一个无状态bean.
Is it secure to use such beans for maintaining a user session (shopping cart etc)? I read a book about ejb 3.0 and I know that the same stateless bean could be used with many clients.
使用具有所有ejb功能(事务,线程安全性等)的托管bean的最佳方法是什么?我的意思是,除了Java EE 5中的托管Bean +具有实现+ ejb注入的ejb接口之外,还有其他方法吗?
What's the best approach to use a managed bean with all ejb features (transactions, thread safety etc)? I mean any other way than managed bean + ejb interface with implementation + ejb injection as in Java EE 5?
我使用GlassFish 3.1 WebProfile
I use GlassFish 3.1 WebProfile
推荐答案
无状态Bean无法维护购物车或会话;这就是无状态"的意思.
Stateless beans cannot maintain shopping carts or session; that's what "stateless" means.
您需要有状态EJB或在Web层中进行操作.那是唯一可以维持会话的地方.
You need either a stateful EJB or to do it in the web tier. Those are the only places where session is maintained.
这篇关于我可以将EJB Stateless Bean与CDI一起使用来维护用户会话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!