Implementing @Async services
It's not only controllers that can be non-blocking in Spring 5; the service layer can too. Just like its lower versions, Spring 5 also supports asynchronous services to implement concurrent service transactions in the background. This recipe will highlight Callable<T> and @Async Spring native services.
Getting started
Open the current Maven project ch08 and implement some methods that run asynchronously.
How to do it...
Spring 5 offers asynchronous service layer that can be called by any asynchronous controllers. Let us build these service layer using the following steps:
- Before we start this recipe, the use of
@Asyncrequires a thorough and appropriate configuration of anyTaskExecutortype inSpringAsynchConfigincluding some proxy-related configurations on@EnableAsyncannotation. - Create a package
org.packt.web.reactor.serviceand addEmployeeServicewith some template methods:
public interface EmployeeService {
public CompletableFuture<List<Employee...