我的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。
答案 0 :(得分:0)
尝试这种方式来查找Bean
CalculatorRemote calculator = (CalculatorRemote)ic.lookup("java:comp/env/CalculatorBean");
编辑:
对于GlassFish,无需添加
删除java:comp/env/
部分。
CalculatorRemote calculator = (CalculatorRemote)ic.lookup("CalculatorBean");