Java???·-RMI??
???????????? ???????[ 2014/11/20 10:21:51 ] ????????Java ??????? ????
????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 }
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11