NameNotFoundException when calling a EJB in Weblogic 10.3

前端 未结 1 1020
太阳男子
太阳男子 2021-02-06 08:27

I have a EJB defined as this:

package com.foo;
@Stateless (mappedName=\"HelloWorld\")
public class HelloWorldBean implements HelloWorld, HelloWorldLocal
....


        
相关标签:
1条回答
  • 2021-02-06 08:46

    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 (the mappedName() in @Stateless) and the specific Remote Business Interface, separated by a "#":

    InitialContext ic = new InitialContext();
    FooBusiness1 bean1 = (FooBusiness1) ic.lookup("FooEJB#com.acme.FooBusiness1");
    FooBusiness2 bean2 = (FooBusiness2) ic.lookup("FooEJB#com.acme.FooBusiness2");
    

    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 :

    FooBusiness bean = (FooBusiness) ic.lookup("FooEJB");
    

    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 a jndi.properties configuration file for other environments) but this is just a side note. Then, you should look up com.foo.HelloWorld, the Remote Interface, not com.foo.HelloWorldBean, the implementation:

    InitialContext ic = new InitialContext();
    (HelloWorld) ic.lookup("HelloWorld#com.foo.HelloWorld");
    

    And if your bean has only one Remote Business Interface, this should work:

    (HelloWorld) ic.lookup("HelloWorld");
    
    0 讨论(0)
提交回复
热议问题