Announcement Announcement Module
No announcement yet.
same session ID in different threads Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • same session ID in different threads

    I'm trying to use session scoped beans in my full client environment, since I want to use the same configuration as in the web. I was able to create a web applicationContext to communicate with my beans.

    Everything worked fine so far. But to make my client GUI thread safe I have to place the communication with my beans in their own thread. This mens I get the exception:

    "Error creating bean with name 'scopedTarget.serviceRechte': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found:"

    That is obvious, since the communication thread was not bound to the context and even if he were, each thread would have it's own ID and would cause the @ScopedProxy to create a new bean.

    Is there any possibility to configure a thrad that he looks like another?

  • #2
    I solved the Problem. To achieve that two threads have the same session, I had to use the following Code in the communication thread:

    MockHttpServletRequest request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    Both, the event dispatcher thread and the communication thread obviously need the same variable of getSession().