Create a stateful session bean from a stateless bean

 ̄綄美尐妖づ 提交于 2019-12-11 07:29:41

问题


The context is the following :

An client application uses a stateless session bean in order to login on an EJB server application. If the login is successful, the client should get a stateful session bean in order to perform some transactions on his personal data. However, I would want that the login method returns a new instance of this stateful session bean such that a client should not be able to manually call this session bean and perform transactions without being authenticated. Is it possible ?

In my stateless bean I have the following code :

@Resource 
private SessionContext context;
...

public StatefulBeanRemote login(username, password) {
  if (ok) {
    StatefulBeanRemote bean = (StatefulBeanRemote) context.lookup("StatefulBeanRemote");
    return bean; 
  }

The lookup always fail. I don't know what I am doing wrong...


回答1:


The lookup you're performing is the same as:

new InitialContext().lookup("java:comp/env/StatefulBeanRemote");

Have you defined an EJB reference to StatefulBeanRemote? Perhaps that is all you need:

@EJB(name="StatefulBeanRemote", beanInterface=StatefulBeanRemote.class)
public class MyClass {
    @Resource
    private SessionContext context;
    ...
}


来源:https://stackoverflow.com/questions/10373220/create-a-stateful-session-bean-from-a-stateless-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!