I have a EJB defined as this:
package com.foo;
@Stateless (mappedName="HelloWorld")
public class HelloWorldBean implements HelloWorld, HelloWorldLocal
....
When it's deployed to Weblogic (WL), it gets the name myBean. I'm not sure if this is important.
I try to call the bean with this code:
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(ht);
tp = (HelloWorld) ic.lookup("HelloWorld#com.foo.HelloWorldBean");
Anyone know why I get the following error?
javax.naming.NameNotFoundException: While trying to lookup 'HelloWorld#com.foo.HelloWorldBean' didn't find subcontext 'HelloWorld#com'.
Resolved '' [Root exception is javax.naming.NameNotFoundException: While trying
to lookup 'HelloWorld#com.foo.HelloWorldBean' didn't find
subcontext 'HelloWorld#com'. Resolved '']; remaining name 'HelloWorld#com/foo/HelloWorldBean'
To lookup a Remote Interface of a Session Bean with multiple Remote Business interfaces (e.g.
com.acme.FooBusiness1
,com.acme.FooBusiness2
), you need to lookup a name derived from the combination of the target ejb's global JNDI name (themappedName()
in@Stateless
) and the specific Remote Business Interface, separated by a "#":In the typical case of a bean only having one Remote Business Interface, this fully-qualified form is not needed. In that case, the bean's JNDI name can be used directly :
That was the theoretical part. Now the practice. In your case, from what I can see, you are accessing the EJB from Weblogic so I'd rather use the no-arg
InitialContext()
constructor (and use ajndi.properties
configuration file for other environments) but this is just a side note. Then, you should look upcom.foo.HelloWorld
, the Remote Interface, notcom.foo.HelloWorldBean
, the implementation:And if your bean has only one Remote Business Interface, this should work: