Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-20983

Cannot inject @Resource in WebSocket endpoint

XMLWordPrintable

    • Hide

      add beans.xml to WEB-INF:

      <beans bean-discovery-mode="all"></beans>

      Show
      add beans.xml to WEB-INF: <beans bean-discovery-mode="all"></beans>
    • ---
    • ---

      @ServerEndpoint
      public class WebSocket {

          @Resource
          ManagedExecutorService mes;

      }

      `mes` is not injected here and will throw an NPE on access. However any @Inject CDI-managed class can be injected.

       REF: https://jakarta.ee/specifications/websocket/2.0/websocket-spec-2.0.html#websocket-endpoints-and-dependency-injection

      "request that an entry from the application component’s environment be injected into the class"

      and

      The specifications for the various application component types describe which classes may be annotated for injection, are summarized in Component classes supporting injection. The component classes with a support level of “Standard” all support Jakarta EE resource injection, as well as PostConstruct and PreDestroy callbacks. In addition, if CDI is enabled—which it is by default—these classes also support CDI injection, as described in Support for Dependency Injection, and the use of interceptors.

      With table at Component classes supporting injection WebSocket classes endpoint support Standard injection.

              rhn-cservice-bbaranow Bartosz Baranowski
              omega09 N L
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: