java – 本地EJB的JNDI查找(没有@EJB)
作者:互联网
我有一个要求,我被要求使用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成功加载.
解决方法:
你试过下面的代码吗?
context.lookup("ejblocal:"+MyObjectInterfaceLocal.class.getName())
Webshpere对远程和本地接口使用不同的默认绑定模式.
标签:java,java-ee,ejb-3-0,ejb,websphere-8 来源: https://codeday.me/bug/20190528/1172147.html