GlassFIsh4 无法注入 WebSocket Endpoint



我正在尝试在GlassFish 4上使用websocket,但CDI似乎不适用于WebSocket。

@ServerEndpoint("/websocket")
public class WebSocket {
    @Inject
    private TestBean bean;
    ......
}

bean将永远null.

我搜索了谷歌,发现有些人说同样的事情,但解决方案可能会有所帮助。

我有这个确切的场景在:

https://github.com/arun-gupta/javaee7-samples/tree/master/websocket/injection

什么是 bean 发现模式.xml ?它应如下所示:

<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                  http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">

最新更新