Spring integrates RMI-Java remote method call

Source: Internet
Author: User

I. Opening Speech

In the previous RMI-Java remote method call blog, the JDK native class is used for remote method call. This article uses the APIS provided by spring to integrate RMI, hoping to help you.


Ii. Core APIs

1. Client: the Core of the client is RmiProxyFactoryBean, which contains two attributes: serviceUrl (Remote Call address) and serviceInterface (Remote Call interface)




2. server: RmiServiceExporter outputs the Bean managed by spring into an RMI service. By packing the Bean in an adapter class, the adapter class is bound to the RMI registry, and proxy the request to the service class.




Iii. Environment preparation

1. Running environment:

Spring2.5, JDK6.0


2. jar package: spring. jar, commons-logging.jar


3. code structure:



4. Code Testing

1. SumService: addition operation interface

public interface SumService {public int getAdd(int a, int b);}

2. SumServiceImpl: addition operation implementation

public class SumServiceimpl implements SumService {public int getAdd(int a, int b) {return a + b;}}

3. Server

public class Server {public static void main(String[] args) {// init spring contextApplicationContext context = new ClassPathXmlApplicationContext("application_context_server.xml");System.out.println("server start!");}}

4. Client

public class Client {private static final Integer NUM_1 = 1;private static final Integer NUM_2 = 2;public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("application_context_client.xml");SumService sumService = (SumService) ctx.getBean("rmiProxyFactoryBean", SumService.class);System.out.println("client sum: " + NUM_1 + " + " + NUM_2 + " = " + sumService.getAdd(NUM_1, NUM_2));}}

5. Configure application_context_server.xml on the server

 
 
  
  
  
  
   
   
   
   
   
  
 

6. Configure application_context_client.xml on the client

 
     
       
           
            
        
   
 

7. Source: http://download.csdn.net/detail/zdp072/7423185



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.