????4.???????????????
1 import java.rmi.Naming;
2 import java.rmi.registry.LocateRegistry;
4 public class SetService {
6     public static void main(String[] args) {
8         try {
10             StudentService studentService=new StudentServiceImpl();
12             LocateRegistry.createRegistry(5008);//???????
14             Naming.rebind("rmi://127.0.0.1:5008/StudentService"?? studentService);
16             System.out.println("?????????");
18         } catch (Exception e) {
20             e.printStackTrace();
22         }
24     }
26 }
????5. ?????????????????RMI???á?
1 import java.rmi.Naming;
3 import java.util.List;
5 public class GetService {
9   public static void main(String[] args) {
11       try {
13           StudentService studentService=(StudentService) Naming.lookup("rmi://127.0.0.1:5008/StudentService");
15           List<Student> list = studentService.getList();
17           for (Student s : list) {
19               System.out.println("??????"+s.getName()+"??????"+s.getAge());
21           }
23       } catch (Exception e) {
25           e.printStackTrace();
27       }
29   }
33 }
????6.???????????
????=============?????============
????????????????????15
???????????????????20
????===============================
??????Spring??????Rmi????
??????Rmi??Spring??????????????????????Rmi???????????
????1.????????????????????????????????????????????????????
????1 package service;
????3 import java.util.List;
????5 public interface StudentService {
????7      List<Student> getList();
????9 }
????2.????????????????????????????????????????????????????????
1 package service;
4 import java.util.ArrayList;
6 import java.util.List;
9 public class StudentServiceImpl implements StudentService {
11  public List<Student> getList() {
13   List<Student> list=new ArrayList<Student>();
15   Student s1=new Student();
17   s1.setName("????");
19   s1.setAge(15);
21   Student s2=new Student();
23   s2.setName("????");
25   s2.setAge(20);
27   list.add(s1);
29   list.add(s2);
31   return list;
33  }
35 }