problem description
use the Spring framework, start a new thread in Service, and use
RequestAttributes ra = RequestContextHolder.getRequestAttributes ();
in the new thread to get null,. Is there any way to solve it?
the environmental background of the problems and what methods you have tried
InService, multithreading is used to optimize the response time, and the RequestContextHolder class is used in some threads, and the return value is empty.
related codes
RequestAttributes ra = RequestContextHolder.getRequestAttributes ();
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
HttpServletRequest request = sra.getRequest ();
System.out.println (request.getContextPath ());
what result do you expect? What is the error message actually seen?
expectation: System.out.println (request.getContextPath ()); prints out the path normally,
actual: RequestAttributes ra = RequestContextHolder.getRequestAttributes ();
ranull.