在 Web 应用程序中 @Inject @Remote EJB

@Inject a @Remote EJB in Web Application

是否可以在 Web 应用程序中 @Inject @Remote EJB? 我 运行 在 Glassfish 5 上,我正在部署一个 EAR (EJB + WAR)。

当我用 @Local 注释 EJB 接口时,CDI 工作,@Remote 不工作。
可能是什么原因?

顺便说一下,使用 @EJB 而不是 @Inject 可以完美地工作,但我要解决 @Inject 问题。

CDI 无法解析远程 ejb bean。根据规格 3.2.2

The unrestricted set of bean types for a session bean contains all local interfaces of the bean and their superinterfaces. If the session bean has a no-interface view, the unrestricted set of bean Declaring a session bean 41 types contains the bean class and all superclasses. In addition, java.lang.Object is a bean type of every session bean. Remote interfaces are not included in the set of bean types.

如果你必须使用 CDI 注入而不是 @EJB

,你可以做的是为远程接口提供现场生产者