Spring Session Scope Bean and Background Thread

Hello Vaadin Fans,

Im facing strange problem right now. Let me describe my problem:

I’ve integrated Vaadin with Spring. I use singletons and session scope beans. Everything works like a charm until I try to use session scope bean in new thread. It ends up with exception:
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

Important parts of my web.xml:


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>     
    
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener> 

My Servlet Code:


    private WebApplicationContext appCtx;
    private Class<? extends Application> appClass;
    private String appBean;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);
        
        appBean = servletConfig.getInitParameter("application");
        if(appBean == null){
            throw new ServletException("The application parameter is missing");
        }
        
        appCtx = WebApplicationContextUtils.getWebApplicationContext(
                servletConfig.getServletContext());
        appClass = (Class<? extends Application>) appCtx.getType(appBean);
    }        
    
    @Override
    protected Application getNewApplication(HttpServletRequest request) throws ServletException {
        return appCtx.getBean(appBean, Application.class);
    }

    @Override
    protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
        return appClass;
    }

Thank you in advance for any pointer in that strange case.

Regards, Satrix

This is probably because an vaadin application is not managed by the spring dispatcher and your session scoped bean does not share the same context as your vaadin app

Any idea how to do it without Dispatcher Servlet ?

I dont think it is possible out of the box.

Running a vaadin application via the spring dispatcher servlet would be a nice feature.

Ok. Thank you very much Danny.

Btw. Still waiting for another idea’s :grin: