无法查找JNDI

时间:2013-05-15 06:16:11

标签: java ejb jndi

我的ejb-jar.xml

中有以下声明
<enterprise-beans>

        <entity>
            <description>Simple CMP Entity bean example</description>
            <ejb-name>CalculatorBean</ejb-name>
            <remote>ejb3.stateless.CalculatorRemote</remote>
            <ejb-class>ejb3.stateless.CalculatorBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.Integer</prim-key-class>
            <reentrant>false</reentrant>
        </entity>
 </enterprise-beans>

我尝试从我的servlet中查找如下;

 CalculatorRemote calculator = (CalculatorRemote)ic.lookup("java/comp/env/:CalculatorBean");

但是它说找不到指定的名称。

我为CalculatorRemoteCalculatorBean创建了课程。

以下是CalculatorRemote

@Remote
public interface CalculatorRemote {

    public float add(float x, float y);

    public float subtract(float x, float y);

    public float multiply(float x, float y);

    public float division(float x, float y);
}

CalculatorBeanCalculatorRemote的实现。 ic是InitialContext。

1 个答案:

答案 0 :(得分:0)

尝试这种方式来查找Bean

 CalculatorRemote calculator = (CalculatorRemote)ic.lookup("java:comp/env/CalculatorBean");

编辑:

对于GlassFish,

无需添加 删除java:comp/env/部分。

 CalculatorRemote calculator = (CalculatorRemote)ic.lookup("CalculatorBean");