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).
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...