Spring Tutorials

Spring Tutorial

Introduction of Spring Framework

Advantages and Disadvantages of Spring Framework

Features of Spring Framework

Basic concept of Spring Framework

Architecture of Spring Framework

Modules of Spring Framework

Goal of Spring Framework

Create Application of Spring without any IDE

Create Application of Spring in Eclipse IDE

Create Application of Spring in MYEclipse IDE

Important JAR of Spring Framework

IOC container in Spring Framework

Bean and Applicationcontext container in Spring Framework

Example of Spring BeanFactory Container in Spring Framework

Example of Spring ApplicationContext Container in Spring Framework

Bean in Spring Framework

Lifecycle of Bean in Spring Framework

Scope of Bean in Spring Framework

Autowiring in Spring Framework

Dependency Injection in Spring Framework

Constructor-based Dependency Injection Example in Spring Framework

Setter-based Dependency Injection Example in Spring Framework

Introduction of AOP in Spring Framework

Core concept and Goal of AOP in Spring Framework

AOP Proxies in Spring framework

XML Schema Based AOP in Spring Framework

AOP Xml based Configuration Example in Spring Framework

Example of Declaring AOP Advices in Spring Framework

AOP AspectJ Annotation with Example in Spring Framework

Declaring an aspect and pointcut using Annotation in Spring Framework

Declaring AOP Advices using Annotation Example in Spring Framework

DAO support in Spring Framework

Introduction of Spring JDBC Framework in Spring Framework

Introduction of Spring JdbcTemplate in Spring Framework

Example of Spring JdbcTemplate class in Spring framework

Example of Executing SQL statements in Spring Framework

Example of Executing DDL statements in Spring Framework

SQL Stored Procedure in Spring Framework

Example of NamedParameterJdbcTemplate in Spring Framework

Example of RowMapperJdbcTemplate in Spring Framework

Introduction of ORM Framework in Spring Framework

Integration of Spring with Hibernate in Spring Framework

Integration of Spring with JPA in Spring Framework

Introduction of Spring Expression Language (SpEL) in Spring Framework

Example of Spring Expression Language (SpEL) in Spring framework

Example of Spring EL in XML and Annotation in Spring Framework

Language Reference with SpEL in Spring Framework

Operators in Spring Expression Language(SpEL) in Spring Framework

Variable in Spring Expression Language(SpEL) in Spring Framework

Introduction of Spring Framework Transaction Management in Spring Framework

Spring Framework Transaction Abstraction

Spring Declarative Transaction Management in Spring Framework

Spring Programmatic Transaction Management in Spring Framework

Introduction of Spring OXM (Object XML Mapping) in Spring Framework

Integration of Spring with Jaxb Example in Spring framework

Example of Spring with Xstream in Spring Framework

Example of Spring with Castor in Spring Framework

Remote Method Invocation(RMI) in Spring Framework

Spring and RMI Integration with Example in Spring Framework

Example of Spring and Httpinvoker in Spring Framework

Example of Spring and Hessian in Spring Framework

Integration of Spring with JMS in Spring Framework

Introduction of Webservice in Spring Framework

Spring Web Services in Spring Framework

Web Services with Jax-WS in Spring framework

Exposing and Exporting servlet-based Web Services using JAX-WS in Spring Framework

Accessing Web Services using JAX-WS in Spring Framework

Introduction of JMS in Spring Framework

JMS Messaging Models in Spring Framework

Using Spring JMS in Spring Framework

Sending and Receiving a Message Using JMS API in Spring Framework

Introduction of JMX (Java Management Extension) in Spring Framework

Integrating Beans with JMX in Spring Framework

Creating a MBeanServer in Spring Framework

Introduction Java Mail with Spring in Spring Framework

Example of Java Mail with spring in Spring Framework

Introduction of EJB(Enterprise JavaBeans) in Spring Framework

Introduction of EJB(Enterprise JavaBeans) Integration in Spring Framework

Integration of Spring With Struts 2 Example in Spring Framework

Spring MVC

Spring MVC

adplus-dvertising
Spring and RMI Integration with Example
Previous Home Next

Exposing services using RMI

Using Spring’s support for RMI, you can transparently expose your services through the RMI infrastructure. After having this set up, you basically have a configuration similar to remote EJBs, except for the fact that there is no standard support for security context propagation or remote transaction propagation.

Spring provides an easy way to run RMI application by the help of following classes:

  1. org.springframework.remoting.rmi.RmiProxyFactoryBean
  2. org.springframework.remoting.rmi.RmiServiceExporter classes.

RmiServiceExporter: This is the exportation service for the rmi object. This service can be accessed via plain RMI or RmiProxyFactoryBean.

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

Technology used to run this Example
  1. Spring 3.0
  2. Eclipse IDE
  3. Tomcat Server

There are some following step to make an Application using RMI with Spring as , The following example show how to write a simple Java SpringRMI application using RMI. To start with it, let us have working Eclipse IDE in place and follow the following steps to developed a Java Application:

Step1: Create a Java Project with a name SpringRMIntegration and create a package com.r4r under the src folder in the created project.

Step2: Create a interface Square.java under the com.r4r package that containing one sq(square) metod.

package com.r4r;
public interface Square {
	int sq(int number);
}

Step3: Create a Java Class SquareIml.java .This class provides the implementation of Square interface.

package com.r4r;
public class SquareImpl implements Square {
	@Override
	public int sq(int number) {
	return number*number;
}

Step4: Following are the list of JAR files required for this application, build configuration path and add the External Jars as given below.

  1. Spring Core jar files
  2. Spring Remoting jar files
  3. Spring AOP jar files

Step5: Create a xml file applicationContext.xml. In this xml file we define the bean for SquareImpl 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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="squareBean" class="com.r4r.SquareImpl"></bean>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">

<property name="service" ref="squareBean"></property>
<property name="serviceInterface" value="com.r4r.Square"></property>
<property name="serviceName" value="SquareService"></property>
<property name="replaceExistingBinding" value="true"></property>
<property name="registryPort" value="1080"></property>
</bean>

</beans>

Step6: Create another xml file client-beans.xml. In this xml file, we define bean for RmiProxyFactoryBean. now we need to define two properties of this class.

  1. serviceUrl
  2. serviceInterface
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="squareBean" 
class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" 
value="rmi://localhost:1080/SquareService"></property>
<property name="serviceInterface" value="com.r4r.Square"></property>
</bean>

</beans>

Step7: Create a Java Class RMI.java.It is simply getting the instance of ApplicationContext.

package com.r4r;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class RMI{
public static void main(String[] args){
ApplicationContext context = 
new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("Waiting for requests from client");
} }

Step8: Create a Java Class Client.java.It is simply getting the instance of Square and call the method.

package com.r4r;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Client {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("client-beans.xml");
Square square = (Square)context.getBean("squareBean");
System.out.println(square.sq(10));
} }

Step9: Run this Application. First Run the RMI.java

Now Run Client.java.

Previous Home Next