Injecting a static EJB, nonsense?

后端 未结 3 1709
离开以前
离开以前 2020-12-06 11:12

I want to write this piece of code :

@Stateless
public class MyEjb
{
    @EJB
    private static MyOtherEjbWhichIWantStatic myOtherEjb;
}

I

3条回答
  •  孤街浪徒
    2020-12-06 11:33

    From Java EE 5 specification injection of static EJBs is only allowed in application client main classes.

    For all classes except application client main classes, the fields or methods must not be static. Because application clients use the same lifecycle as J2SE applications, no instance of the application client main class is created by the application client container. Instead, the static main method is invoked. To support injection for the application client main class, the fields or methods annotated for injection must be static.

提交回复
热议问题