Utility.java Bar bar = (Bar) context.lookup("java:comp/env/ejb/bar");
I don't understand this example. If Utility.java needs a Bar, shouldn't it use @EJB in Utility.java? Why @EJB is used in FooBean.java? I don't see how these 2 java files are related at all.
Without looking at the code in the FooBean, i can only guess that the Utility.java class is being used in this bean. Going by the name of the "Utility" class, i guess its an unmanaged object - which means that you cannot use injection in this class. Effectively, you cannot use @EJB injection to get hold of the "Bar" bean. And that the reason why the Bar bean is being injected in the ENC of the FooBean so that the utility class can look it up from the ENC (java:comp/env namespace) of the FooBean.