Javatpoint Logo

91-9990449935

 0120-4256464

Spring and RMI Integration

Spring RMI lets you expose your services through the RMI infrastructure.

Spring provides an easy way to run RMI application by the help of org.springframework.remoting.rmi.RmiProxyFactoryBean and org.springframework.remoting.rmi.RmiServiceExporter classes.


RmiServiceExporter

It provides the exportation service for the rmi object. This service can be accessed via plain RMI or RmiProxyFactoryBean.


RmiProxyFactoryBean

It is the factory bean for Rmi Proxies. It exposes the proxied service that can be used as a bean reference.


Example of Spring and RMI Integration

Let's see the simple steps to integration spring application with RMI:

  1. Calculation.java
  2. CalculationImpl.java
  3. applicationContext.xml
  4. client-beans.xml
  5. Host.java
  6. Client.java

Required Jar files

To run this example, you need to load:

  • Spring Core jar files
  • Spring Remoting jar files
  • Spring AOP jar files

download all the jar files for spring including core, web, aop, mvc, j2ee, remoting, oxm, jdbc, orm etc.


1) Calculation.java

It is the simple interface containing one method cube.


2) CalculationImpl.java

This class provides the implementation of Calculation interface.


3) applicationContext.xml

In this xml file we are defining the bean for CalculationImpl class and RmiServiceExporter class. We need to provide values for the following properties of RmiServiceExporter class.

  1. service
  2. serviceInterface
  3. serviceName
  4. replaceExistingBinding
  5. registryPort

4) client-beans.xml

In this xml file, we are defining bean for RmiProxyFactoryBean. You need to define two properties of this class.

  1. serviceUrl
  2. serviceInterface
5) Host.java

It is simply getting the instance of ApplicationContext. But you need to run this class first to run the example.


6) Client.java

This class gets the instance of Calculation and calls the method.


How to run this example

First Compile and Run the Host.java

Then, Compile and Run the Client.java