在 Weblogic 10.3 中调用 EJB 时出现 NameNotFoundException
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要查找具有多个远程业务接口(例如
com.acme.FooBusiness1
、com.acme.FooBusiness2
)的会话Bean的远程接口,您需要查找派生的名称来自目标 ejb 的全局 JNDI 名称(@Stateless
中的mappedName()
)和特定远程业务接口的组合,以“#”分隔:如果 Bean 仅具有一个远程业务接口,则不需要这种完全限定的形式。在这种情况下,可以直接使用 bean 的 JNDI 名称:
这就是理论部分。现在练习。就您的情况而言,据我所知,您正在从 Weblogic 访问 EJB,因此我宁愿使用无参数
InitialContext()
构造函数(并使用jndi.properties
code> 其他环境的配置文件)但这只是一个旁注。然后,您应该查找com.foo.HelloWorld
(远程接口),而不是com.foo.HelloWorldBean
(实现):如果您的 bean 只有一个远程业务接口,这应该有效:
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: