Skip to content
Advertisement

java.lang.IllegalStateException: No thread-bound request found, exception in aspect

Following is my aspect:

JavaScript

I do not get any compile time errors but I do following exception when I start my jetty server:

nested exception is 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.

One thing to note here is, if I remove “logAroundService” method, I do not get any exceptions.

Advertisement

Answer

You shouldn’t autowire a HttpServletRequest in your aspect as this will tie your aspect to be only runnable for classes that are called from within an executing HttpServletRequest.

Instead use the RequestContextHolder to get the request when you need one.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement