Magazine
 
Spring

INFO: Loading XML bean definitions from
class path resource [rmi.xml]point3
Sep 28, 2007 3:53:10 PM
org.springframework.remoting.rmi.
RmiClientInterceptor prepare
INFO: Using service interface [rmserver] for
RMI stub [rmi://localhost/rmserver] - directly
implemented Sep 28, 2007 3:53:10 PM
org.springframework.aop.framework.
DefaultAopProxyFactory <clinit>
INFO: CGLIB2 not available: proxyTargetClass
feature disabled
Hai Amit

Here we have removed the ‘lookup’ code in the client side.

The Server side of RMI

Spring also supports the server side of RMI. Here the service itself is written with spring and it is exposed as an RMI service. Here the bean is written as a simple JavaBean. Also we need not to generate the stub and skeleton using ‘rmic’ command and manually add it to RMI registry. Instead of these traditional procedure ‘RmiServiceExporter’ is used to export any Spring managed bean as an RMI service. It wraps the bean in an adapter class. The adapter class is then bound to RMI registry and the proxies request the service.

<bean
class=”org.springframework.remoting.rmi.
RmiServiceExporter”>
<property name=”service1">
<ref bean=”service1"/>
</property>
<property name=”serviceName”>
<value>service1</value>
</property>
<property name=”serviceInterface”>
<value>service1</value>
</property>
</bean>

The ‘serviceName property’ indicates the name of service and ‘serviceInterface’ specifies the interface implemented by the service. There is no need of ‘serviceUrl’ here. First set the path and classpath as before.

 

Next edit the service i.e. rmservice.xml

1. D:\springdemo\rmservice.java

public interface rmservice {
String getresult(String s);
}

2. D:\springdemo\rmserviceimpl.java

public class rmserviceimpl implements
rmservice {
public static void main(String args[]) {
System.out.println(“ready”);
}
public rmserviceimpl() {
System.out.println(“constructor ok”);
}
public String getresult(String a) {
return “Hai”+a;
}
}

3. D:\springdemo\rmservice.xml

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD
BEAN//EN”
”http://www.springframework.org/dtd/
spring-beans.dtd”>
<beans>
<bean
class=”org.springframework.remoting.rmi.
RmiServiceExporter”>
<property name=”service”>
<value>rmservice</value>
</property>
<property name=”serviceName”>
<value>service1</value>
</property>
<property name=”serviceInterface”>
<value>rmservice</value>
</property>
</bean>
<bean id=”rmservice” class=”rmserviceimpl”>
</bean>
/beans>

Oct 2007 | Java Jazz Up | 44
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78,   Download PDF