Spring Framework implementation--remote method invoke RMI code Demo

Source: Internet
Author: User

1, spring_rmi02_server service side 02

1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:context= "Http://www.springframework.org/schema/context"5xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"6xmlns:tx= "Http://www.springframework.org/schema/tx"7xsi:schemalocation="8http//Www.springframework.org/schema/beans9http//www.springframework.org/schema/beans/spring-beans-3.2.xsdTenhttp//Www.springframework.org/schema/context Onehttp//www.springframework.org/schema/context/spring-context-3.2.xsd Ahttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP -http//www.springframework.org/schema/aop/spring-aop.xsd -http//Www.springframework.org/schema/tx thehttp//www.springframework.org/schema/tx/spring-tx-3.0.xsd "> -          -<!--Scan Package base directory-- -<context:component-scan base- Package= "Com.wisezone" ></context:component-scan> +     <!--configuring RMI-->21 <bean class= "Org.springframework.remoting.rmi.RmiServiceExporter" > 22 <property name= "ServiceName" value= "Hello" ></property>23 <property name= "service" ref= "Helloservic Eimpl "></property>24 <property name=" Serviceinterface "value=" Com.wisezone.service.IHelloService "> </property>25 <property name= "Registryport" value= "1199" ></property>26 </bean>     -</beans>
1  Package Com.wisezone.service; 2 3  Public Interface Ihelloservice {4     5      Public string SayHello (String msg); 6 }
1  PackageCom.wisezone.service.impl;2 3 ImportOrg.springframework.stereotype.Service;4 5 ImportCom.wisezone.service.IHelloService;6 7 @Service8  Public classHelloserviceimplImplementsIhelloservice {9 Ten @Override One      Publicstring SayHello (String msg) { A          -SYSTEM.OUT.PRINTLN ("Service side accepts message:" +msg); -         return"Hello-->>" +msg; the     } -  -}
1  Packagecom.wisezone.test;2 3 ImportOrg.springframework.context.ApplicationContext;4 ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;5 6  Public classPublish {7     8      Public Static voidMain (string[] args) {9         TenApplicationContext AC =NewClasspathxmlapplicationcontext ("Beans.xml"); One     } A}

2. spring_rmi02_client Client 02

1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:context= "Http://www.springframework.org/schema/context"5xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"6xmlns:tx= "Http://www.springframework.org/schema/tx"7xsi:schemalocation="8http//Www.springframework.org/schema/beans9http//www.springframework.org/schema/beans/spring-beans-3.2.xsdTenhttp//Www.springframework.org/schema/context Onehttp//www.springframework.org/schema/context/spring-context-3.2.xsd Ahttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP -http//www.springframework.org/schema/aop/spring-aop.xsd -http//Www.springframework.org/schema/tx thehttp//www.springframework.org/schema/tx/spring-tx-3.0.xsd "> -          -<!--Scan Package base directory-- -<context:component-scan base- Package= "Com.wisezone" ></context:component-scan> +     <bean class= "Org.springframework.remoting.rmi.RmiProxyFactoryBean" >21 <property name= "Serviceu RL "value=" Rmi://localhost:1199/hello "></property>22 <property name=" Serviceinterface "value=" com.wise Zone.service.IHelloService "></property>23 </bean> -      -</beans>
1  Package Com.wisezone.service; 2 3  Public Interface Ihelloservice {45      Public string SayHello (String msg); 6 }
1  PackageCom.wisezone.impl;2 3 ImportJavax.annotation.Resource;4 5 ImportOrg.springframework.stereotype.Service;6 7 ImportCom.wisezone.service.IHelloService;8 9 @ServiceTen  Public classUserserviceimpl { One  A @Resource -     PrivateIhelloservice HelloService; -      the      Public voidTest () { -SYSTEM.OUT.PRINTLN ("Client sends message:" +helloservice.sayhello ("im WINDOW7SP1 flagship")); -     } -      +}
1  Packagecom.wisezone.test;2 3 ImportOrg.springframework.context.ApplicationContext;4 ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;5 6 ImportCom.wisezone.impl.UserServiceImpl;7 8  Public classTest {9      Public Static voidMain (string[] args) {TenApplicationContext AC =NewClasspathxmlapplicationcontext ("Beans.xml"); OneUserserviceimpl Userserviceimpl = (Userserviceimpl) ac.getbean ("Userserviceimpl"); A userserviceimpl.test (); -     } -}

Publish order: Publish the server first, then publish the client

Results:

Spring Framework implementation--remote method invoke RMI code Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.