Java EE 7: How-to inject an EJB into a WebSocket ServerEndpoint?

孤人 提交于 2019-11-28 18:47:43

(just restating what I wrote into comment to get this question from "unanswered" list)

You should checkou out Tyrus CDI sample/test.

It demonstrates list what you can do with current implementation. We are always open for new test cases, but there are some issues with the spec itself - standard Request scopes don't work for WebSocket runtime, because it handles messages outside of servlets service/doFilter methods. See WEBSOCKET_SPEC-196 and WEBSOCKET_SPEC-197.

For me. annoting the websocket with @Stateful and EJB object declaration with @EJB did the work.

@Stateful
@ServerEndpoint(value = "/profileregistration")
public class ProfileRegistrationEndpoint {


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