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

Creating a Java RMI service


The Java RMI is a Java remote method invocation technology; a client executes a method ocated on a server, the Java RMI service.

In this recipe, we will set up a Java RMI service that will expose the methods of a normal Java class. The service will be part of an existing Spring web application but will use its own port.

Getting ready

The server will expose the methods of the UserService interface:

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

The UserService interface is implemented by UserServiceImpl:

public class UserServiceImpl implements UserService {
  private List<User> userList = new LinkedList<User>();

  public UserServiceImpl() {
    User user1 = new User("Merlin", 777);
    userList.add(user1);
    
    User user2 = new User("Arthur", 123);
    userList.add(user2);
  }
  
  public List<User> findAll() {
    return userList;
  }
  
  public void addUser(User user...