Java Reference
In-Depth Information
public class RmiServer {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("rmi-server.xml");
}
}
In this configuration, the server will launch; among the output you should see a message indicating
that an existing RMI registry could not be found.
Invoking an RMI Service
By using Spring's remoting facilities, you can invoke a remote service just like a local bean. For example,
you can create a client that refers to the weather service by its interface.
package com.apress.springenterpriserecipes.weather;
...
public class WeatherServiceClient {
private WeatherService weatherService;
public void setWeatherService(WeatherService weatherService) {
this.weatherService = weatherService;
}
public TemperatureInfo getTodayTemperature(String city) {
List<Date> dates = Arrays.asList(new Date[] { new Date() });
List<TemperatureInfo> temperatures =
weatherService.getTemperatures(city, dates);
return temperatures.get(0);
}
}
In a client bean configuration file, such as client.xml located in the classpath root, you can use
RmiProxyFactoryBean to create a proxy for the remote service. Then you can use this service as if it were
a local bean (e.g., inject it into the weather service client).
<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-3.0.xsd">
<bean id="client"
class="com.apress.springenterpriserecipes.weather.WeatherServiceClient">
<property name="weatherService" ref="weatherService" />
</bean>
Search WWH ::




Custom Search