远程业务接口的 Glassfish ejb 引用解析错误
我已经创建了非常基本的 EJB3 有状态 bean,但无法远程访问它。 我得到:
引起:javax.naming.NamingException:远程业务接口com.s9120.ejb.Calculator的ejb引用解析错误[根异常是java.lang.ClassNotFoundException:com.s9120.ejb.Calculator]
我有1个bean和1个接口。 看起来接口没有部署(我使用的是GlassFish): 下面是代码:
package com.calc.ejb;
import javax.ejb.Remote;
@Remote
public interface Calculator {
public Double multiply(Double multiplier, Double multiplicand);
public Double divide(Double dividend, Double divisor);
public Double add(Double addend, Double augend);
public Double subtract(Double minuend, Double subtrahend);
public void saveToMemory(Double number);
public Double retrieveFromMemory();
}
Bean:
package com.calc.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateful;
/**
* Session Bean implementation class CalculatorBean
*/
@Stateful
@Remote(Calculator.class)
public class CalculatorBean implements Calculator{
/* Implementation */
}
访问它:
context = new InitialContext();
Calculator calculator = (Calculator) context.lookup("java:global/Zad3_s9120/CalculatorBean");
我是否必须执行一些步骤才能使接口可用于会话 bean? 我使用“添加和删除”服务器菜单从 Eclipse 添加它。
I've created very basic EJB3 stateful bean but can't access it remotely.
I'm getting:
Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.s9120.ejb.Calculator [Root exception is java.lang.ClassNotFoundException: com.s9120.ejb.Calculator]
I have 1 bean and 1 interface.
It looks like the interface is not deployed (I'm using GlassFish):
Here is the code:
package com.calc.ejb;
import javax.ejb.Remote;
@Remote
public interface Calculator {
public Double multiply(Double multiplier, Double multiplicand);
public Double divide(Double dividend, Double divisor);
public Double add(Double addend, Double augend);
public Double subtract(Double minuend, Double subtrahend);
public void saveToMemory(Double number);
public Double retrieveFromMemory();
}
Bean:
package com.calc.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateful;
/**
* Session Bean implementation class CalculatorBean
*/
@Stateful
@Remote(Calculator.class)
public class CalculatorBean implements Calculator{
/* Implementation */
}
Accessing it:
context = new InitialContext();
Calculator calculator = (Calculator) context.lookup("java:global/Zad3_s9120/CalculatorBean");
Do I have to do some steps to make interface available to session bean?
I'm adding it from Eclipse with "Add and Remove" server menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,你们有不同的包裹。
您已将接口定义为:
但您的异常告诉您:
也许您的客户端项目中没有适当的类?
顺便说一句:您不需要在接口和 EJB 上都指定
@Remote
。您只能在 EJB 上执行@Remote(MyClass.class)
操作,或在接口上执行@Remote
操作。From what I can see, you have different packages.
You've defined interface as:
but your exception tells you about:
Perhaps you don't have appropriate class in your client project?
BTW: You don't need to specify
@Remote
on both - the interface and EJB. You can do only@Remote(MyClass.class)
on EJB or@Remote
on interface.