给EJB一个JNDI [英] giving an EJB a JNDI

查看:207
本文介绍了给EJB一个JNDI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个远程接口的EJB:

I have created and EJB with a remote interface:

@Stateless
public class TestSessionBean implements TestSessionRemote 
{

    public void businessMethod() 
    {
            System.out.println ("***businessMethod");
    }
}

我从另一个组件(例如servlet )通过以下方式在服务器上运行:

I to access it from another component (e.g a servlet) running on the server via:

ic = new InitialContext();
ic.lookup("myEJB");

我正在使用netBeans 6.5.1和glassfish v2。

I am using netBeans 6.5.1 and glassfish v2.

我如何做?

谢谢,
Ido

Thanks, Ido

推荐答案

实际上ejb3使用默认的命名约定,我没有找到一种方法来解决。

actually ejb3 use a default naming convention, wich i've not found a way to get around.

您的bean的名称将是:
TestSessionBean#package.TestSessionBean

The name for your bean would be something like: TestSessionBean#package.TestSessionBean

您可以使用远程服务来执行此操作。

To acess your remote service you can do something like this

InitialContext ctx = new InitialContext();
ctx.lookup(interfaceClass.getSimpleName()+"#"+interfaceClass.getName());

其中interfaceClass是远程界面的类。

where interfaceClass is the class of your remote interface.

请注意,您没有为该Web服务器定义一个远程接口(或本地的)。您可能无法从另一个上下文中获取该对象。

do note you havent defined a remote interface(or local for that matter) for that webserver. you mightnot be able to acess theejb from another context.

至于更改实际上我不认为可能通过anotations的名称。不确定

As for changing the name that is actually i dont think is possible through anotations. not sure though

这篇关于给EJB一个JNDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆