我需要使用JNDI查找来加载远程和本地EJB,因此不需要@EJB注释。
我的EJB定义如下:
@Remote
public interface MyObjectInterfaceRemote extends MyObjectInterface {
}@Local
public interface MyObjectInterfaceLocal extends MyObjectInterface {
}public interface MyObjectInterface {
// A bunch of methods which both remote and local ejbs will inherit
}@Remote(MyObjectInterfaceRemote.class)
@Local(MyObjectInterfaceLocal.class)
public class MyObjectEJB implements MyObjectInterfaceLocal, MyObjectInterfaceRemote {
//implementation of all methods inherited from MyObjectInterface.
}我正在使用这段代码来查找远程EJB:
private MyObjectInterfaceRemote getEJB() throws NamingException {
InitialContext context = new InitialContext();
return (MyObjectInterfaceRemote) context.lookup(MyObjectInterfaceRemote.class.getName());
}它工作得很好,但是如果我做了另一个像这样的方法:
private MyObjectInterfaceLocal getLocalEJB() throws NamingException {
InitialContext context = new InitialContext();
return (MyObjectInterfaceLocal) context.lookup(MyObjectInterfaceLocal.class.getName());
}我得到了
javax.naming.NameNotFoundException:
Context: Backslash-PCNode03Cell/nodes/Backslash-PCNode03/servers/server1,
name: MyObjectInterfaceLocal: First component in name MyObjectInterfaceLocal not found.
[Root exception is org.omg.CosNaming.NamingContextPackage.NotFound:
IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
[...]我遗漏了什么?我是否需要使用不同的东西来查找本地ejb?
注:如果我使用
@EJB
MyObjectInterfaceLocal ejb;本地ejb将成功加载。
发布于 2014-11-27 10:32:17
你试过下面的代码吗?
context.lookup("ejblocal:"+MyObjectInterfaceLocal.class.getName())Webshpere对远程和本地接口使用不同的默认绑定模式。
https://stackoverflow.com/questions/27166631
复制相似问题