Announcement Announcement Module
Collapse
No announcement yet.
Log4J shuts down too early Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Log4J shuts down too early

    I have written a small test to see how init and destroy methods are working in Spring Web Application.

    Here is a small bean I created:
    Code:
    public class InitDestroyTester {
      Logger logger = Logger.getLogger(InitDestroyTester.class);
    
      public void init() {
         logger.info("init() called");
      }
    
      public void destroy() {
         logger.info("destroy() called");
      }
    }
    
    <bean id="initDestroyTester" class="...InitDestroyTester" init-method="init" destroy-method="destroy" />
    When the WebApplicationContext is being initialized, everything's just fine, I can see log saying "init() called".

    However when webapp is removed from context (i.e. when I redeploy my webapp in Tomcat), I can't see "destroy() called" message in log.

    I figured out that it is only because Log4J was shutdown BEFORE InitDestroyTester could log something upon "destroy" call.

    How can I configure Log4J to be shutdown only after WebApplicationContext was disposed?
    Thanks in advance.

  • #2
    Works for me, here are relevant parts of the logging :

    - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy]
    - Creating shared instance of singleton bean 'initDestroyTester'
    - init() called
    ... reload ...
    - Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy}
    - destroy() called
    - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [initDestroyTester]; Root of BeanFactory hierarchy]
    - Creating shared instance of singleton bean 'initDestroyTester'
    - init() called

    Do you use Log4jConfigListener ?
    see http://www.springframework.org/docs/...gListener.html

    Maarten

    Comment


    • #3
      Yes, I use the *Listener option. However it might be that my current version Tomcat is 2.3 Servlet version container, I'll try *Servlet option to see if it works better.

      Thanks for the hint!

      Comment

      Working...
      X