users@hk2.java.net

Re: RequestScoped: dispose not called after request is completed

From: John Wells <john.wells_at_oracle.com>
Date: Mon, 30 Sep 2013 10:40:32 -0400

I'm not sure why this would happen. However I think this is more of a
question for the implementors of RequestScoped, which is Jersey (I
think). You might want to re-post this question in the Jersey mail group...

On 9/28/2013 3:16 PM, Andreas Lundblad wrote:
> Hi,
>
> I'm having troubles setting up injection of objects that are request
> scoped.
>
> I've tried the following:
>
> bindFactory(new Factory<MyService>() {
>
> @Override
> public MyService provide() {
> System.out.println("Creating a MyService...");
> return new MyService(System.currentTimeMillis());
> }
>
> @Override
> public void dispose(MyService s) {
> System.out.println("Disposing MyService");
> }
>
> }).in(RequestScoped.class).to(MyService.class);
>
>
> The MyService object is created, it is injected as it should be, but
> dispose is never called.
>
> Any idea why?
>
> I'm using Jersey 2.3 and Grizzly.
>
> (This post describes the same issue:
> http://stackoverflow.com/questions/17396165/using-jersey-2-0-how-do-you-register-a-bindable-instance-per-request
> )
>
> best regards,
> Andreas Lundblad