[英]ClassNotFoundException when calling EJB running on weblogic 10.3 from app running on weblogic 10.0
[英]NameNotFoundException when calling a EJB in Weblogic 10.3
我有一个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'
要查找具有多个远程业务接口的会话Bean的远程接口(例如com.acme.FooBusiness1
, com.acme.FooBusiness2
),您需要查找从目标ejb的全局JNDI名称( mappedName()
在@Stateless
)和特定的远程业务接口,用“#”分隔:
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所以我宁愿使用no-arg InitialContext()
构造函数(并使用jndi.properties
配置文件用于其他环境)但这只是一个方面注意。 然后,你应该查看com.foo.HelloWorld
,远程接口,而不是com.foo.HelloWorldBean
,实现:
InitialContext ic = new InitialContext();
(HelloWorld) ic.lookup("HelloWorld#com.foo.HelloWorld");
如果您的bean只有一个远程业务接口,这应该工作:
(HelloWorld) ic.lookup("HelloWorld");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.