I have a Jersey2 application that runs on an embedded Grizzly server - a setup identical to this example: https://github.com/jersey/jersey/tree/2.18/examples/https-clientserver-grizzly/src/main/java/org/glassfish/jersey/examples/httpsclientservergrizzly
I have integrated it with swagger-jersey2-jaxrs_2.10 and it has been working OK. Now that swagger-core 1.5 came out and it produces Swagger 2.0 definitions, I would like to upgrade to that version.
Having followed the Swagger setup instructions from this site: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5 I discovered that Swagger won't work any more as it requires a ServletContext instance to be injected, and ServletContext fields annotated with @Context are not being injected in my project (they show as nulls).
So my actual question is: does jersey-container-grizzly2-servlet support ServletContext at all? Is there any way I can get ServletContext to be injected by altering my project's config? Or should I look into ways of integrating swagger-core 1.5 that don't require a ServletContext?
This is how I got it working:
Add these dependencies to your pom.xml:
Register ApiListingResource and SwaggerSerializers:
Initialize Grizzly, Jersey and Swagger: