Question

Im currently working on a grizzly, spring and jersey project and i have encountered:

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.
    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
    at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
    ... 32 more

Based on the stacktrace (and also by the results when i google), i should register a listener in the web.xml

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

So my question is, how will i register the listener to the grizzly server given that i dont have a web.xml?

Was it helpful?

Solution

Without seeing more of your code, my guess would be to use a ServletHandler - check out the example source in the top of the Javadocs for this class:

A normal spring application would have a listener registered for context startup, and then the dispatch servlet for most other things, so you should be able to amend the example code to do this.

Something like (totally untested):

sa.setServlet(new org.springframework.web.servlet.DispatcherServlet());
sa.addListener(org.springframework.web.context.ContextLoaderListener.class.getName());
sa.addContextParameter("contextConfigLocation", "beans.xml");
sa.setServletPath("/*");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top