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).
Have comments or feedback on what I wrote? Please share them below!
Other posts you may like...