Java – warn: failed to register destroy callback

This warning message appears a lot in my log For each managed bean, as long as it expires After the given time, because I use myfaces band

I'm already on my web Org. XML is defined in springframework. web. context. request. Requestcontextlistener, and there is no spring jar in my classpath (that is, it is not a class loading problem)

The facesrequesattribute document says:

Purchasecontroller is actually a simple managed bean (which does not extend any and only implements serializable), annotated with @ controller

UPDATE1:

@Beans in scope ("request") and @ scope ("session") seem to be affected So I wonder if this warning poses any danger to the correct traffic That is, if you really need these callbacks If not, I will skip the warning with lo4j configuration

Update 2:

I dug further, as if it only happened sometimes If a listener is used, requestcontextholder Currentrequestattributes() returns servletrequestattributes instead of facesrequesattributes So it seems that sometimes the listener does not work and the current property will not be set in the requestcontextholder

Update 3:

I opened debugging for requestcontextlistener. Here is the result:

07:21:31,518 DEBUG RequestContextListener:69 - Bound request context to thread: org.apache.catalina.connector.RequestFacade@1190ae9
07:21:31,518 DEBUG RequestContextListener:89 - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@1190ae9
07:21:31,538  WARN FacesRequestAttributes:121 - Could not register destruction callback [org.springframework.beans.factory.support.DisposableBeanAdapter@11aa152] for attribute 'org.apache.myfaces.orchestra.conversation.AccessScopeManager' because FacesRequestAttributes does not support such callbacks
07:21:31,541  WARN FacesRequestAttributes:121 - Could not register destruction callback [org.springframework.beans.factory.support.DisposableBeanAdapter@1552393] for attribute 'localeController' because FacesRequestAttributes does not support such callbacks
....and so on,other request and session beans

The request was corrupted before attempting to access the bean This is strange. Is it possible that this is due to a problem with the servlet container implementing listener processing?

Solution

In the Javadoc of facesrequest attributes, we can see:

Moreover, in fact, the registerdestructioncallback() method of facesrequesattributes does not do much:

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 requestcontextlistener (you announced) will take care of the job Its requestdestroyed (servletrequestevent) method is as follows:

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());
       }
   }
}

If you look at the Javadoc of servletrequestattributes #requestcompleted():

So, I think you can safely skip warn and log4j configuration (possibly confirmed by a little debugging session)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>