1

I'm trying to use websocket on GlassFish 4, but CDI seems doesn't work for WebSocket.

@ServerEndpoint("/websocket")
public class WebSocket {

    @Inject
    private TestBean bean;

    ......
}

The bean will always be null.

I have searched google, and find some people saying about the same thing, but nome of the solutions could help.

bjgoblige
  • 13
  • 2

1 Answers1

2

I have this exact scenario working at:

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

What is bean-discovery-mode in your beans.xml ? It should look like:

<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">

Arun Gupta
  • 3,965
  • 5
  • 31
  • 39