Java Reference
In-Depth Information
public class WeatherServiceImpl implements WeatherService {
public List<TemperatureInfo> getTemperatures(String city, List<Date> dates) {
List<TemperatureInfo> temperatures = new ArrayList<TemperatureInfo>();
for (Date date : dates) {
temperatures.add(new TemperatureInfo(city, date, 5.0, 10.0, 8.0));
return temperatures;
Exposing an RMI Service
Suppose you want to expose the weather service as an RMI service. To use Spring's remoting facilities
for this purpose, create a bean configuration file such as rmi-server.xml in the classpath root to define
the service. In this file, you declare a bean for the weather service implementation and export it as an
RMI service by using RmiServiceExporter .
<beans xmlns=""
<bean id="weatherService"
class="" />
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="WeatherService" />
<property name="serviceInterface"
value="" />
<property name="service" ref="weatherService" />
There are several properties you must configure for an RmiServiceExporter instance, including the
service name, the service interface, and the service object to export. You can export any bean configured
in the IoC container as an RMI service. RmiServiceExporter will create an RMI proxy to wrap this bean
and bind it to the RMI registry. When the proxy receives an invocation request from the RMI registry, it
will invoke the corresponding method on the bean.
By default, RmiServiceExporter attempts to look up an RMI registry at localhost port 1099. If it
can't find the RMI registry, it will start a new one. However, if you want to bind your service to another
running RMI registry, you can specify the host and port of that registry in the registryHost and
registryPort properties. Note that once you specify the registry host, RmiServiceExporter will not start
a new registry, even if the specified registry doesn't exist.
To start a server that provides the RMI weather service, run the following class to create an
application context for the preceding bean configuration file:
Search WWH ::

Custom Search