Victor Wang
Victor Wang

Reputation: 51

javax.naming.NameNotFoundException: Name ejb/com not found in context "java:comp/env"

Error message is as mentioned in title. Below code snippet is used in various places across different project packages. ejb-jar.xml and binding files are defined properly. The main reason I am asking is I am not sure why it is working well in some places, but not the other.

Context context = (Context)initialContext.lookup("java:comp/env");
Object localObj = context.lookup("ejb/com/notification");

Upvotes: 3

Views: 7131

Answers (1)

Gas
Gas

Reputation: 18020

It is usually better to use just one line:

Object localObj = context.lookup("java:comp/env/ejb/com/notification");

and since you are using java:comp/env you must have ejb reference defined, either using deployment descriptor or annotation. For classes used in web module, it must be defined in web.xml (or EJB annotation in any servlet), for classes used from EJB components, it must be defined in each 'parent' EJB again either using ejb-jar.xml or annotation.

Upvotes: 1

Related Questions