Embedded Jetty - IllegalStateException: No SessionManager

一笑奈何 提交于 2019-12-04 01:29:38

I believe the issue comes from the fact that you are instantiating a ServletContextHandler rather than a WebappContext

Try

val webapp = new WebappContext();

or

val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS)
webapp.setSessionHandler(new SessionHandler())

From the ServletContextHandler javadoc

 [...]construction of a context with ServletHandler and optionally session and security handlers [...]

The word optionally is likely the key here.

In jetty 9.4, to enable a very simple session handler for a servlethandler:

private static void setSessionEnableContext( Server server,ServletHandler handlerServlet ) {
      // Specify the Session ID Manager        
    SessionIdManager idmanager = new DefaultSessionIdManager(server);
    server.setSessionIdManager(idmanager);
   // Specify the session handler
    SessionHandler sessionsHandler = new SessionHandler();       
    handlerServlet.setHandler(sessionsHandler);           
}

ok, I feel a little foolish, this issue was in my servlet, I was accessing the request in a child thread, that accessed the session when the request was out of scope. And in googling the error, it sent me down the wrong path because the error message was a bit vague. Thanks to BGR for the reply.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!