I would like to introduce a sessionless CDI bean in stateless EJB. For EJB access time, you should use the correct instance of the session cdi bean (i.e., the one that is in the caller's session). I know that I can solve this with EJB, but I would really like to know if this is allowed with CDI. Since EJBs and Servlet are working in the same war, I would suggest that they have the same thread and the container should be able to determine the correct session bean in EJB?
For example:
EJB:
@Stateless
@LocalBean
public class StatelessSessionBean {
@Inject
Instance<SessionData> sessionData;
public String testMethod() {
SessionData bean = sessionData.get();
String result = "Retrieved bean " + bean + " with UUID "+ bean.uuid + ". Created on: " + new SimpleDateFormat("dd.MM.yyyy HH:mm").format(bean.creationDate);
return result;
}
}
CDI Bean:
@SessionScoped
public class SessionData implements Serializable {
String uuid;
Date creationDate;
public SessionData() {
uuid = UUID.randomUUID().toString();
creationDate = new Date();
}
}
EJB , . , testMethod CDI bean, HTTPSession . , /http , .
CDI Provider Instance, , bean ?
, , BeanManager SessionData, , .
, !