Spring Remoting with Hessian and Burlap – 用黑纱和麻布制作的春景图

最后修改: 2017年 2月 26日

1. Overview


In the previous article titled “Intro to Spring Remoting with HTTP Invokers” we saw how easy is to set up a client/server application that leverages remote method invocation (RMI) through Spring Remoting.

前一篇题为 “Spring Remoting与HTTP Invokers介绍”的文章中,我们看到通过Spring Remoting建立一个利用远程方法调用(RMI)的客户端/服务器应用程序是多么容易。

In this article, we will show how Spring Remoting supports the implementation of RMI using Hessian and Burlap instead.

在这篇文章中,我们将展示Spring Remoting如何支持使用HessianBurlap代替RMI的实现。

2. Maven Dependencies


Both Hessian and Burlap are provided by the following library that you will need to include explicitly in your pom.xml file:



You can find the latest version on Maven Central.

您可以在Maven Central上找到最新版本。

3. Hessian


Hessian is a lightweight binary protocol from Caucho, the makers of the Resin application server. Hessian implementations exist for several platforms and languages, Java included.


In the following subsections, we will modify the “cab booking” example presented in the previous article to make the client and the server to communicate using Hessian instead of the Spring Remote HTTP based protocol.

在下面的小节中,我们将修改上一篇文章中介绍的 “出租车预订 “的例子,使客户端和服务器使用Hessian而不是基于Spring Remote HTTP协议进行通信。

3.1. Exposing the Service


Let’s expose the service by configuring a RemoteExporter of type HessianServiceExporter, replacing the HttpInvokerServiceExporter previously used:


@Bean(name = "/booking") 
RemoteExporter bookingService() {
    HessianServiceExporter exporter = new HessianServiceExporter();
    exporter.setService(new CabBookingServiceImpl());
    exporter.setServiceInterface( CabBookingService.class );
    return exporter;

We can now start the server and keep it active while we prepare the client.


3.2. Client Application


Let’s implement the client. Here again, the modifications are quite simple — we need to replace the HttpInvokerProxyFactoryBean with a HessianProxyFactoryBean:


public class HessianClient {

    public HessianProxyFactoryBean hessianInvoker() {
        HessianProxyFactoryBean invoker = new HessianProxyFactoryBean();
        return invoker;

    public static void main(String[] args) throws BookingException {
        CabBookingService service
          = SpringApplication.run(HessianClient.class, args)
          service.bookRide("13 Seagate Blvd, Key Largo, FL 33037"));

Let’s now run the client to make it connect to the server using Hessian.


4. Burlap


Burlap is another lightweight protocol from Caucho, based on XML. Caucho stopped maintaining it a long time ago, and for that, its support has been deprecated in the newest Spring releases, even though it is already present.


Therefore you should reasonably continue using Burlap only if you have applications that are already distributed and that cannot easily be migrated to another Spring Remoting implementation.

因此,只有当您的应用程序已经发布,并且不能轻易迁移到另一个Spring Remoting实现时,您才应该合理地继续使用Burlap

4.1. Exposing the Service


We can use Burlap exactly in the same way that we used Hessian — we just have to choose the proper implementation:


@Bean(name = "/booking") 
RemoteExporter burlapService() {
    BurlapServiceExporter exporter = new BurlapServiceExporter();
    exporter.setService(new CabBookingServiceImpl());
    exporter.setServiceInterface( CabBookingService.class );
    return exporter;

As you can see, we just changed the type of exporter from HessianServiceExporter to BurlapServiceExporter. All the setup code can be left unchanged.


Again, let’s start the server and let’s keep it running while we work on the client.


4.2. Client Implementation


We can likewise swap Hessian for Burlap at the client side, changing out HessianProxyFactoryBean with BurlapProxyFactoryBean:


public BurlapProxyFactoryBean burlapInvoker() {
    BurlapProxyFactoryBean invoker = new BurlapProxyFactoryBean();
    return invoker;

We can now run the client and see how it connects successfully to the server application using Burlap.


5. Conclusion


With these quick examples, we showed how it is easy with Spring Remoting to choose among different technologies to implement remote method invocation and how you can develop an application being completely unaware of the technical details of the protocol used to represent the remote method invocation.

通过这些快速的例子,我们展示了使用Spring Remoting在不同的技术中选择实现远程方法调用是多么的容易,以及你如何在完全不知道用于表示远程方法调用的协议的技术细节的情况下开发一个应用程序。

As usual, you’ll find the sources over on GitHub, with clients for both Hessian and Burlap and the JUnit test CabBookingServiceTest.java that will take care of running both the server and the clients.