首页 > 代码库 > 基于java工程开发RMI服务端

基于java工程开发RMI服务端

ServiceRegist.java

import java.rmi.Remote;

import java.rmi.RemoteException;

public interface ServiceRegist extends Remote{

  public user login(String userName, String password) throws RemoteException;

}

ServiceRegisterImpl.java

public class ServiceRegisterImpl extends UnicastRemoteObject implements ServiceRegist{

  private UserDao userDao;

  public ServiceRegisterImpl() throws RemoteException{super();}

   public user login(String userName, String password) throws RemoteException{

    return userDao.login(userName,password);

  }

}


发布

public class RMIServer{

  public static void main(String args[]){

    ServiceRegist sr = new ServiceRegistImpl();

    LocateRegistry.createRegistry(8888);

    String url = "rmi://localhost:8888/serviceRegistry";

    Naming.bind(url,sr);

    System.out.println("服务调度器启动成功");

  }

}