remote object implements illegal remote interface
来源:互联网 发布:java 锁 synchronized 编辑:程序博客网 时间:2024/04/29 16:04
最近在学习EJb,用EJB写一个使用远程对象完成计算时抛出的异常remote object implements illegal remote interface
程序如下:
/***********接口*****************/
public interface calc extends Remote {
public int calc(int a,int b);
}
/***********实现类*****************/
public class calcImpl extends UnicastRemoteObject implements calc {
public calcImpl() throws RemoteException {
super();
}
public int calc(int a, int b) {
if(a>b){
return a-b;
}else if(a==b){
return a*b;
}else{
return a+b;
}
}
}
/****************测试类*****************/
public static void main(String[] args) {
try {
Registry re=LocateRegistry.createRegistry(2000);
calcImpl calc=new calcImpl();
re.bind("calc", calc);
System.out.println("服务器已经启动了");
} catch (Exception e) {
e.printStackTrace();
}
}
然后就是将接口导出,放到另一个工程里测试,测试工程的代码如下:
public static void main(String[] args) {
String url="rmi://localhost:2000/calc";
try {
calc c=(calc) Naming.lookup(url);
int result=c.calc(10, 5);
System.out.println("计算的结果是:"+result);
} catch (Exception e) {
e.printStackTrace();
}
}
很简单的一个问题,当我启动服务器的时候,程序报了一个异常:
我到网上查了一下,很多都是英文的,有中文的也没有说一个所以然来,所以只好自己去出问题,我把抛出的异常仔细看了一下子,原来原来异常信息告诉我,自己定义的接口里面的方法有问题,我仔细看了一下方法,方法好像少了点什么,原来使用远程方法调用都必须抛出一个RemoteException,因为 网络出现类似机器故障或者网络阻塞等问题时会产生RemoteException。在接口定义的方法里throws RemoteException,问题就解决了。
- remote object implements illegal remote interface
- remote object implements illegal remote interface
- Designing a Remote Interface
- Implementing a Remote Interface
- java Remote Object
- 用ADIL设计 Remote interface
- BlazeDS入门——Remote Object Service
- flex httpservice vs Remote object 优点
- BlazeDS Tutorial – Remote Object Service
- Flex Remote Object IE 问题(转)
- weblogic Failed to bind remote object
- HOWTO: Use Interface-based remote objects with config files
- Invalid (i.e. remote) invocation of local interface (null container)
- iOS设备的流量分析:Remote Virtual Interface
- iOS设备的流量分析:Remote Virtual Interface
- iOS 手机抓包 使用 remote virtual interface
- 编程式调试node程序的利器chrome-remote-interface
- remote communication
- OnPaint 和 OnDraw函数的区别 (转)
- POJ1944 Fiber Communications
- asp.net导出成EXCEL
- MFC--滚动视图窗口(CScrollView)使用双缓冲问题
- 对联广告不滚动的问题 asp.net 页面
- remote object implements illegal remote interface
- Io exception: Connection refused(DESCRIPTION=(ERR=1153)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(ADDRESS=(PROTOCOL=TCP)(POR
- J2ME贪吃蛇源代码——200行左右,包含详细注释
- SSL证书导出备份与导入安装指南
- 重新在MyEclipse启动时调出Workspace的设置
- 不应忽视的HTML优化
- 解决win7下vc++6.0无法打开文件的方法
- J2ME游戏代码示例——俄罗斯方块
- The Triangle--poj--1163