¡¡¡¡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ÉÙÁË£¬×Ô¼º×¢ÒâÌí¼Ó¡£