WARN: Could not register destruction callback

后端 未结 2 1398
感情败类
感情败类 2020-12-30 07:36

15:11:14,676 WARN FacesRequestAttributes:121 - Could not register destruction callback [org.springframework.beans.factory.support.DisposableBeanAdapter@1059f

相关标签:
2条回答
  • 2020-12-30 08:05

    In the javadoc of FacesRequestAttributes, we can read:

    Note: In contrast to ServletRequestAttributes, this variant does not support destruction callbacks for scoped attributes, neither for the request scope nor for the session scope. If you rely on such implicit destruction callbacks, consider defining a Spring RequestContextListener in your web.xml.

    And, indeed, the registerDestructionCallback() method of FacesRequestAttributes doesn't do much things:

    public void registerDestructionCallback(String name, Runnable callback, int scope) {
        if (logger.isWarnEnabled()) {
            logger.warn("Could not register destruction callback [" + callback + "] for attribute '" + name +
                            "' because FacesRequestAttributes does not support such callbacks");
        }
    }
    

    But my understanding is that the RequestContextListener (that you have declared) will take care of this job. Its requestDestroyed(ServletRequestEvent requestEvent) method is shown below:

    public void requestDestroyed(ServletRequestEvent requestEvent) {
       ServletRequestAttributes attributes =
               (ServletRequestAttributes) requestEvent.getServletRequest().getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
       ServletRequestAttributes threadAttributes =
               (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
       if (threadAttributes != null) {
           // We're assumably within the original request thread...
           if (attributes == null) {
               attributes = threadAttributes;
           }
           RequestContextHolder.resetRequestAttributes();
           LocaleContextHolder.resetLocaleContext();
       }
       if (attributes != null) {
           attributes.requestCompleted();
           if (logger.isDebugEnabled()) {
               logger.debug("Cleared thread-bound request context: " + requestEvent.getServletRequest());
           }
       }
    }
    

    And if you look at the javadoc of ServletRequestAttributes#requestCompleted():

    Executes all request destruction callbacks and updates the session attributes that have been accessed during request processing.

    So, I think that you can safely skip the WARN with log4j configuration (maybe confirm this with a little debugging session though).

    0 讨论(0)
  • 2020-12-30 08:06

    I tried adding

    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    

    as suggested by erhan14 on this forum post.

    And that warning disappeared for me. Hope it helps.

    0 讨论(0)
提交回复
热议问题