How to do it...

Another way of creating asynchronous services is using Future<T> and CallableFuture<T> as return values. Let us create these asynchronous APIs in our services by following these steps:

  1. Open the EmployeeServiceImpl implementation class. Study the service methods readEmployees() and readEmployee(id). The readEmployees() passes the whole employee record retrieval transaction to the @Controller in a CompletableFuture<Employee> form. On the other side, the readEmployee(id) passes the whole result as a Future<Employee> object.
  2. Add another service class, namely DepartmentService, with the following templates:
public interface DepartmentService { public CompletableFuture<List<Department>> readDepartments(); public void addDepartment(DepartmentForm ...

Get Spring 5.0 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.