I'm trying to convert a sequential series of calls of spring service to be asynchronous.
I have annotated the method with @Async and added taskExecutor configuratinos.
I can see that the method is now being invoked asynchronously but I'm having issues with SecurityContextHolder.getContext() throwing this error:
java.util.concurrent.ExecutionException: java.lang.NullPointerException
Would really appreciate any insights. Thanks!
The SecurityContext is stored in a ThreadLocal. So if you access it from a new thread that didn't set it anywhere, then the SecurityContext is null.
Update: Added Threadlocal javadoc link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With