After upgrading Spring versions, I noticed that SecurityContextHolder.getContext() was null inside an AuditorAware type used as part of an @Async method.
Following some answers, here, I added these to my Spring Boot Application class: ...
@Bean
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("Async-");
return executor;
}
@Bean
public DelegatingSecurityContextAsyncTaskExecutor taskExecutor(ThreadPoolTaskExecutor executor) {
return new DelegatingSecurityContextAsyncTaskExecutor(executor);
}
...And everything runs great!
However, given that the Async methods were already being executed asynchronously without the creation of a ThreadPoolTaskExecutor Bean, shouldn't I be able to @Autowired that Bean/Component for my DelegatingSecurityContextAsyncTaskExecutor, instead of having to create a new ThreadPoolTaskExecutor?