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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.