簡體   English   中英

本地 EJB 的 JNDI 查找(無 @EJB)

[英]JNDI Lookup of local EJB (no @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 對遠程和本地接口使用不同的默認綁定模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM