我正在使用 spring 框架,这是我用来检索 HttpSession
对象的代码:
ServletRequestAttributes attr;
try {
attr = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
} catch (Exception e) { }
HttpSession session = attr.getRequest().getSession(false);
Holder class to expose the web request in the form of a thread-bound RequestAttributes object.
因此,在容器创建的用于处理请求的线程之外不会看到它。有没有办法在某个子线程中检索 session ?
最佳答案
不,没有。在 Servlet API 中, session 是请求对象的一个属性。因此,如果您没有请求,您会检索众多现有 session 中的哪一个?
关于java - 从子线程获取http session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32867387/