jersey
  1. jersey
  2. JERSEY-1982

@PreDestroy not invoked on root resource

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: backlog
    • Component/s: None
    • Labels:
      None

      Description

      It seems that Jersey 2 no longer invokes @PreDestroy on a root resource when used with the JDK's bundled http server (JdkHttpServerFactory). @PostConstruct is properly as expected.

      This was working as expected in Jersey 1.x. Is this no longer the case? Is there a work-around?

        Activity

        Hide
        Miroslav Fuksa added a comment -

        Jersey 2 does not call @PreDestroy nor @PostConstruct for standard resources. These methods are called for CDI beans and for Application class.

        Check the org.glassfish.jersey.server.CloseableService. You can inject it to your resource method, resource or provider using @Context annotation and then register your Closeable (using add() method) which will be called when request is finished.

        Show
        Miroslav Fuksa added a comment - Jersey 2 does not call @PreDestroy nor @PostConstruct for standard resources. These methods are called for CDI beans and for Application class. Check the org.glassfish.jersey.server.CloseableService. You can inject it to your resource method, resource or provider using @Context annotation and then register your Closeable (using add() method) which will be called when request is finished.
        Hide
        spamdaemon added a comment -

        Actually, it does call @PostConstruct (at least at the time of writing this issue) which I think should have been paired with a @PreDestroy.

        At any rate, I did indeed go the route with the cleanup handler.

        Show
        spamdaemon added a comment - Actually, it does call @PostConstruct (at least at the time of writing this issue) which I think should have been paired with a @PreDestroy. At any rate, I did indeed go the route with the cleanup handler.
        Hide
        Miroslav Fuksa added a comment -

        You are right. For standard JAX-RS resources PostConstruct is called but not PreDestroy. This should be fixed and PreDestroy methods should also be called.

        Note: when implementing please make sure to handle correctly singleton and request scopes.

        Show
        Miroslav Fuksa added a comment - You are right. For standard JAX-RS resources PostConstruct is called but not PreDestroy. This should be fixed and PreDestroy methods should also be called. Note: when implementing please make sure to handle correctly singleton and request scopes.
        Hide
        Stephan202 added a comment -

        To be clear: this affects not just resources, but other JAX-RS @Providers (such as ContainerResponseFilter implementations) as well. (I.e., @PostConstruct is called, but @PreDestroy isn't.)

        Show
        Stephan202 added a comment - To be clear: this affects not just resources, but other JAX-RS @Providers (such as ContainerResponseFilter implementations) as well. (I.e., @PostConstruct is called, but @PreDestroy isn't.)
        Hide
        Stephan202 added a comment -

        This issue was mostly resolved by JERSEY-2574, but not completely: Feature instances are still "left out".

        Tangentially related is the fact that the jersey-test-framework-provider-inmemory doesn't support @PreDestroy at all (while the Jetty and Grizzly providers do). Not a deal breaker, but unfortunate.

        Show
        Stephan202 added a comment - This issue was mostly resolved by JERSEY-2574 , but not completely: Feature instances are still "left out". Tangentially related is the fact that the jersey-test-framework-provider-inmemory doesn't support @PreDestroy at all (while the Jetty and Grizzly providers do). Not a deal breaker, but unfortunate.

          People

          • Assignee:
            Unassigned
            Reporter:
            spamdaemon
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: