我正在使用 Java RMI 编写客户端-服务器程序,但出现错误:
java.security.AccessControlException:访问被拒绝(“java.net.SocketPermission”“127.0.0.1:1099”“connect,resolve”)
我的代码如下所示:
package xxx;
import java.rmi.Naming;
import java.rmi.RemoteException;
public class Server extends Engine implements RemoteInterface {
public Server() {
super();
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
Naming.rebind("Test", this);
System.out.println("Bound in registry!");
} catch(Exception ex) {
System.out.println(ex);
}
}
@Override
public void test() throws RemoteException {
System.out.println("test() invoked");
}
}
怎么了?