AFAIK you *can* still register instances. (The documentation text is a bit misleading).
The way to work around your issue is documented in Jochen’s link: Instead of defining @context fields at the class level you have to move them to the method parameters. - Matthias Von: [email protected] <[email protected]> Im Auftrag von James Kern Gesendet: Donnerstag, 3. September 2020 18:09 An: dropwizard-user <[email protected]> Betreff: Re: Jersey context injection in resources not working with Dropwizard 2.0 I'm wondering if there are examples of how to work around this when the resource class constructor takes parameters? Does this changes mean I need to integrate a DI framework? On Sunday, August 25, 2019 at 1:12:20 PM UTC-4 [email protected]<mailto:[email protected]> wrote: Hi Paolo, see https://github.com/dropwizard/dropwizard/issues/2781 and https://github.com/dropwizard/dropwizard/wiki/Upgrade-guide-1.3.x-to-2.0.x#context-injection-on-fields-in-resource-instances. Cheers, Jochen Am 22.08.2019 um 16:04 schrieb Paolo Simonazzi <[email protected]>: I'm testing dropwizard 2.0 and found out that the current version of Jersey does not support @Context injection when registering resources as object. It worked in the version included in Dropwizard 1.3.9. I think the Jersey bug is: https://github.com/eclipse-ee4j/jersey/issues/3438 Example resource: @Path("/") public class MyResource { @Context private HttpServletRequest httpServletRequest; ... } Registering as object env.jersey().register(new MyResource()); the httpServletRequest will be null. A workaround is to register the resource by class: env.jersey().register(MyResource.class); But it can be very cumbersome if the resource must be passed some parameters in the constructor (we need to inject them too, or pass them is some other way). So I would like to know if someone found a more convenient way to manage this problem until it is (hopefully) fixed upstream. Thanks -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/ce07832e-97e9-4a1c-a51b-71e4d789084en%40googlegroups.com<https://groups.google.com/d/msgid/dropwizard-user/ce07832e-97e9-4a1c-a51b-71e4d789084en%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/79d2d5ca401b4369a011eb4f7b75f0ee%40MSX-L104.msx.ad.zih.tu-dresden.de.
