Using SpringFrameWork @Async for methods that return void
Simply return
return new AsyncResult<>(null);
Try the following:
@Async
public void saveUser(String userid) {
User user = new User();
user.setUserId(userid);
mongoTemplate.save(user);
}
Future needs to be used only when there is return type other than void.
The only value a Void
can have is null
. So all you need is
User user = new User();
user.setUserId(userid);
mongoTemplate.save(user)
return new AsyncResult<Void>(null);