在 Weblogic 10.3 中调用 EJB 时出现 NameNotFoundException

发布于 2024-08-08 15:18:43 字数 962 浏览 4 评论 0原文

我有一个 EJB 定义如下:

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

当它部署到 Weblogic (WL) 时,它的名称为 myBean。我不确定这是否重要。

我尝试使用以下代码调用 bean:

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");

有人知道为什么我收到以下错误吗?

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'

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2024-08-15 15:18:43

要查找具有多个远程业务接口(例如com.acme.FooBusiness1com.acme.FooBusiness2)的会话Bean的远程接口,您需要查找派生的名称来自目标 ejb 的全局 JNDI 名称(@Stateless 中的 mappedName())和特定远程业务接口的组合,以“#”分隔

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

:如果 Bean 仅具有一个远程业务接口,则不需要这种完全限定的形式。在这种情况下,可以直接使用 bean 的 JNDI 名称:

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

这就是理论部分。现在练习。就您的情况而言,据我所知,您正在从 Weblogic 访问 EJB,因此我宁愿使用无参数 InitialContext() 构造函数(并使用 jndi.properties code> 其他环境的配置文件)但这只是一个旁注。然后,您应该查找 com.foo.HelloWorld(远程接口),而不是 com.foo.HelloWorldBean(实现):

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

如果您的 bean 只有一个远程业务接口,这应该有效:

(HelloWorld) ic.lookup("HelloWorld");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文