-2
我尝试在applicationListener impl中获取sessionId。它在session.getId()中引发NULLPointerException。我想知道为什么它有异常。会话已创建,但无法访问其他属性。以下是我的代码。春天注入httpSession ApplicationListener
@Component
public class MyEventListener implements ApplicationListener<MyEvent> {
@Autowired
HttpSession session;
@Override
public void onApplicationEvent(final QuotePricingEvent quoteEvent) {
LOGGER.error("Session id: {}, userid: {}", session.getId());
}
}
编辑
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.addListener(RequestContextListener.class);
}
请提供[mcve]和完整的堆栈跟踪。 –