Javaѧϰ֮·-RMIѧϰ

·¢±íÓÚ£º2014-11-20 09:54

×ÖÌ壺´ó ÖРС | ÉÏһƪ | ÏÂһƪ | ÎÒҪͶ¸å

 ×÷Õߣº·º·º¶øÕ„    À´Ô´£º51TestingÈí¼þ²âÊÔÍø²É±à

¡¡¡¡3.½ÓÒ»ÏÂÀ´ÔÚapplicationContext.xmlÅäÖÃÐèÒªµÄÐÅÏ¢
¡¡¡¡a.Ê×Ïȶ¨Òå·þÎñbean
¡¡¡¡<bean id="studentService" class="service.StudentServiceImpl"></bean>
¡¡¡¡b.¶¨Òåµ¼³ö·þÎñ
¡¡¡¡<bean class="org.springframework.remoting.rmi.RmiServiceExporter"
¡¡¡¡p:service-ref="studentService"
¡¡¡¡p:serviceInterface="service.StudentService"
¡¡¡¡p:serviceName="StudentService"
¡¡¡¡p:registryPort="5008"
¡¡¡¡/>
¡¡¡¡Ò²¿ÉÒÔÔö¼Óp:registryHostÊôÐÔÉèÖÃÖ÷»ú
¡¡¡¡c.ÔÚ¿Í»§¶ËµÄapplicationContext.xmlÖж¨ÒåµÃµ½·þÎñµÄbean(ÕâÀïµÄÀý×ÓÊǰѵ¼³ö·þÎñbeanºÍ¿Í»§¶ËµÄbean·ÅÔÚÒ»¸öapplicationContext.xmlÖеÄ)
¡¡¡¡<bean id="getStudentService"
¡¡¡¡class="org.springframework.remoting.rmi.RmiProxyFactoryBean"
¡¡¡¡p:serviceUrl="rmi://127.0.0.1:5008/StudentService"
¡¡¡¡p:serviceInterface="service.StudentService"
¡¡¡¡/>
¡¡¡¡d.ÅäÖõĶ«Î÷¾ÍÕâô¶à£¬ÊDz»ÊDZÈÉÏÃæµÄÏÖʵҪ·½±ãµÄ¶àѽ£¡ÏÖÔÚÎÒÃÇÀ´²âÊÔÒ»ÏÂ
1 package service;
2 import java.util.List;
3 import org.springframework.context.ApplicationContext;
4 import org.springframework.context.support.ClassPathXmlApplicationContext;
5 public class Test {
6 public static void main(String[] args) {
7   ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
8   StudentService studentService=(StudentService) ctx.getBean("getStudentService");
9   List<Student> list = studentService.getList();
10   for (Student s : list) {
11    System.out.println("ÐÕÃû£º"+s.getName()+",ÄêÁ䣺"+s.getAge());
12   }
13  }
14 }
¡¡¡¡=============¿ØÖÆ̨============
¡¡¡¡ÐÕÃû£ºÕÅÈý,ÄêÁ䣺15
¡¡¡¡ÐÕÃû£ºÀîËÄ,ÄêÁ䣺20
¡¡¡¡=============================
¡¡¡¡ÉÏÃæµÄmian·½·¨ÔËÐпÉÄܻᱨ´í£¬Ó¦¸ÃÊÇspringµÄjarÉÙÁË£¬×Ô¼º×¢ÒâÌí¼Ó¡£
33/3<123
¡¶2023Èí¼þ²âÊÔÐÐÒµÏÖ×´µ÷²é±¨¸æ¡·¶À¼Ò·¢²¼~

¹Ø×¢51Testing

ÁªÏµÎÒÃÇ

¿ì½ÝÃæ°å Õ¾µãµØͼ ÁªÏµÎÒÃÇ ¹ã¸æ·þÎñ ¹ØÓÚÎÒÃÇ Õ¾³¤Í³¼Æ ·¢Õ¹Àú³Ì

·¨ÂɹËÎÊ£ºÉϺ£À¼µÏÂÉʦÊÂÎñËù ÏîÆåÂÉʦ
°æȨËùÓÐ ÉϺ£²©Îª·åÈí¼þ¼¼Êõ¹É·ÝÓÐÏÞ¹«Ë¾ Copyright©51testing.com 2003-2024
ͶËß¼°Òâ¼û·´À¡£ºwebmaster@51testing.com; ÒµÎñÁªÏµ£ºservice@51testing.com 021-64471599-8017

»¦ICP±¸05003035ºÅ

»¦¹«Íø°²±¸ 31010102002173ºÅ