1

我的声明中有以下声明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");

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

我为CalculatorRemote和 也创建了类CalculatorBean

这是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);
}

CalculatorBean是一个实现CalculatorRemote。ic 是 InitialContext。

4

1 回答 1

0

试试这种方式来查找Bean

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

编辑:

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

 CalculatorRemote calculator = (CalculatorRemote)ic.lookup("CalculatorBean");
于 2013-05-15T06:52:29.730 回答