Book Image

Spring Cookbook

Book Image

Spring Cookbook

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Querying an existing Java RMI service


In this recipe, we will configure a Spring web application, so that it will be able to execute a method on an existing RMI service.

Getting ready

We will query the Java RMI service of the previous Creating a Java RMI service recipe.

We need the UserService interface so that our application knows the methods available on the RMI service:

public interface UserService {
  public abstract List<User> findAll();
  public abstract void addUser(User user);
}

User objects will be exchanged over the network, so we need the User class of the previous recipe as well:

public class User implements Serializable {    
  private String name;
  private int age;
  
  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }

  // ... getters and setters
}

In real applications, these classes could be provided to the RMI client as a JAR file.

How to do it…

Here are the steps to query a Java RMI service:

  1. In the Spring configuration, add a RmiProxyFactoryBean...