C H A P T E R 5
■ ■ ■
EJB, Spring Remoting, and Web
In this chapter, you will learn about Spring's support for various remoting technologies, such as EJB,
RMI, Hessian, Burlap, HTTP Invoker, and Web Services. Remoting is a key technology in developing
distributed applications, especially multitier enterprise applications. It allows different applications or
components, running in different JVMs or on different machines, to communicate with each other using
a specific protocol.
Spring's remoting support is consistent across different remoting technologies. On the server side,
Spring allows you to expose an arbitrary bean as a remote service through a service exporter. On the
client side, Spring provides various proxy factory beans for you to create a local proxy for a remote
service so that you can use the remote service as if it were a local bean.
Nowadays, there are two main approaches to developing web services: contract-first and contract-
last . Automatically exposing a bean from the IoC container as a web service means that the service is
contract-last because the service contract is generated from an existing bean. The Spring team has
created a subproject called Spring Web Services (Spring-WS), which focuses on the development of
contract-first web services. In this approach, a service contract is defined first, and code is then written
to fulfill this contract.
5-1. Exposing and Invoking Services Through RMI
You want to expose a service from your Java application for other Java-based clients to invoke remotely.
Because both parties are running on the Java platform, you can choose a pure Java-based solution
without considering cross-platform portability.
Remote Method Invocation (RMI) is a Java-based remoting technology that allows two Java applications
running in different JVMs to communicate with each other. With RMI, an object can invoke the methods
of a remote object. RMI relies on object serialization to marshal and unmarshal method arguments and