Uploaded image for project: 'Causeway'
  1. Causeway
  2. CAUSEWAY-1017

@PreDestroy annotated method is not called

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • core-1.7.0
    • core-1.8.0
    • Core
    • None
    • Windows 7

    Description

      When annotating the DomainService "SimpleObjects" with
      ...
      @PostConstruct
      @Programmatic
      public void init()

      { System.out.println(">>> @PostConstruct init called <<<"); }

      @PreDestroy
      @Programmatic
      public void shutdown()

      { System.out.println(">>> @PreDestroy shutdown called <<<"); }

      ...

      only the @PostConstruct method will be called out of the box.
      Unfortunately, the annotated @PreDestroy method not.

      How to reproduce:
      1) Checkout, build and check that Simpleapp 1.7.0 or 1.8.0-Snapshot is running.
      2) Introduce the mentioned @PostConstruct and @PreDestroy methods
      an go sure, that a message will be logged when message is called.
      3) build and deploy simpleapp-webapp.war to Tomcat v7.x or Tomcat v8.x
      4) See log / use breakpoints to see that @PostConstruct method will be successfully called.

      15:40:18,311 [Schema Thread-2 DEBUG] Schema Transaction closing with connection "org.datanucleus.store.rdbms.datasource.dbcp.PoolingDataSource$PoolGuardConnectionWrapper@74ce8acd"
      >>> @PostConstruct init called <<<
      15:40:24,504 [Reflections Thread-2 INFO ] Reflections took 3181 ms to scan 125 urls, producing 9629 keys and 59986 values

      5) Stop simpleapp-webapp or redeploy it or even stop tomcat
      6) See log / breakpoints and realize that no @PreDestroy method was called.

      Negativ side effect is, that every associated connection to JMS / Elastic Search, ... in @PostConstruct cannot be disconnected easily and cleanly.

      As a workaround I have tried to activate the section in web.xml:

      <!--
      THE FOLLOWING CONFIGURATION IS NOT REQUIRED IF THE WICKET VIEWER IS IN USE.
      IF THE WICKET VIEWER CONFIGURATION IS REMOVED, THEN UNCOMMENT
      -->

      <listener>
      <listener-class>org.apache.isis.core.webapp.IsisWebAppBootstrapper</listener-class>
      </listener>

      <context-param>
      <param-name>deploymentType</param-name>
      <param-value>SERVER_EXPLORATION</param-value>
      </context-param>

      <context-param>
      <param-name>isis.viewers</param-name>
      <param-value>restfulobjects</param-value>
      </context-param>

      even this is not my scenario. Doing this the annotated methods gets called, but I hit the IsisWicketApplication Error:
      Failed to initialize
      com.google.inject.ProvisionException: Guice provision errors:

      1) Error in custom provider, org.apache.isis.core.commons.exceptions.IsisException: Isis Context already set up and cannot be replaced
      at org.apache.isis.core.runtime.runner.IsisInjectModule.provideIsisSystem(IsisInjectModule.java:132)
      at org.apache.isis.core.runtime.runner.IsisInjectModule.provideIsisSystem(IsisInjectModule.java:132)
      while locating org.apache.isis.core.runtime.system.IsisSystem
      for field at org.apache.isis.viewer.wicket.viewer.IsisWicketApplication.system(IsisWicketApplication.java:140)
      while locating webapp.SimpleApplication

      The cool thing is, that this time both annotated method are called:

      16:16:37,713 [Schema Thread-2 DEBUG] Schema Transaction closing with connection "org.datanucleus.store.rdbms.datasource.dbcp.PoolingDataSource$PoolGuardConnectionWrapper@2339e31f"
      >>> @PostConstruct init called <<<
      16:16:45,196 [Reflections Thread-2 INFO ] Reflections took 3259 ms to scan 125 urls, producing 9629 keys and 59986 values
      ...
      INFORMATION: Cleaning up Shiro Environment
      >>> @PreDestroy shutdown called <<<

      16:16:53,198 [IsisContext main INFO ] closing all instances
      16:16:53,198 [IsisWebAppBootstrapper main INFO ] server shut down

      Please fix that issue or assist me in creating a workaround.
      Thanks,
      Peter

      Attachments

        Activity

          People

            danhaywood Daniel Keir Haywood
            bruecp Peter Brückler
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: