79213990

Date: 2024-11-22 07:27:50
Score: 1
Natty:
Report link

I think this is because by default spring doesn't carry SecurityContext holder to new thread that will when you called @Async method where Security Context is not avilable to carry SecurityContext to new threads then you have to do this:

@Bean
 public InitializingBean initializingBean() {
     return () -> SecurityContextHolder.setStrategyName(
    SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
 } 
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @Async
  • Low reputation (0.5):
Posted by: kush parsaniya