NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ
for more details.
I was implementing a custom entity provider
in a Jersey REST
service when I came across an error during deployment: "java.lang.IllegalStateException: Not inside a request scope."
That struck me as a little odd since I was trying to inject a ContainerRequestContext
into a MessageBodyWriter
, which should have been within request scope. After some research and this Jersey issue
I found a solution.
This is what I was trying to do in my class:
...which was throwing this exception...
The solution was to inject a ResourceContext
instead and then look up the ContainerRequestContext
So my injection code became:
...and then to get the ContainerRequestContext
I simply got it from the ResourceContext
This worked with Jersey 2.x
(2.25.1 in my case).
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
If you spot something out of place, please do let me know.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...