Announcement Announcement Module
No announcement yet.
Listener Creation Hierarchy Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listener Creation Hierarchy


    I have a custom Log4jListener class (a class that extends Log4jConfigListener) and I have it registered before the ContextLoaderListener class in my web.xml file.

    I was under the impression that by following this order, the Log4jListener class would be created before the ContextLoaderListener class, but I am finding out that this is not the case: the ContextLoaderListener class is actually being created (ContextLoaderListener#contextInitialized(...) method is being called) before the Log4jListener class (Log4jConfigListener#contextInitialized(...) method is being called). This means that all the spring-beans are also being instantiated prior to the Log4jListener class being created.

    This is preventing my ability to use the logger in spring-beans where I have an init-method attribute since the referred method is called when the particular spring-bean is instantiated, but given what I mentioned above, the Log4jListener class is not yet created. Once the application has started, all subsequent logging works fine as expected.

    Is the order in which the listeners created simply a behavior of the web container (Websphere) and is there a way to change the precedence so that my log4j configuration is in effect prior to the spring-beans being instantiated?
    Also, if registering the Log4jConfigListener before the ContextLoaderListener does not ensure the former's creation first, is there any other reason the Spring documentation recommends "This listener should be registered before ContextLoaderListener in web.xml when using custom log4j initialization?"