服务器:JBoss 7.1.1 EJB 3.0 Eclipse Juno
我正在使用 ejb 3.0 完成我的第一个 Web 服务项目,并且在我的客户端上遇到了问题。对于我的客户,我制作了一个 servlet。问题是当我尝试:
CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");
我在查找时收到 ClassNotFoundException。我从我的 JBoss server.log 得到这个 jndi
[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named CalculatorImp in deployment unit deployment "EJBCalculatorWS.war" are as follows:
java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:app/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:module/CalculatorImp!math.CalculatorOps
我有 2 个 Web 项目,WS 和 Client,都添加到服务器,WS 位于 Client 的构建路径中。
- - - - - - -代码 - - - - - -
界面
package math;
@Local
public interface CalculatorOps {
public int add(int a, int b);
public int subtract(int a, int b);
}
班级
package math;
@Stateless(mappedName="TheCalc")
@WebService
public class CalculatorImp implements CalculatorOps{
@Override
public int add(int a, int b) {
return a+b;
}
@Override
public int subtract(int a, int b) {
return a-b;
}
}
小服务程序
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");
}