加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – WARN:无法注册销毁回调

发布时间:2020-12-14 05:14:56 所属栏目:Java 来源:网络整理
导读:15:11:14,676 WARN FacesRequestAttributes:121 – Could not register destruction callback [org.springframework.beans.factory.support.DisposableBeanAdapter@1059fd6] for attribute ‘purchaseController’ because FacesRequestAttributes does not

15:11:14,676 WARN FacesRequestAttributes:121 – Could not register destruction callback [org.springframework.beans.factory.support.DisposableBeanAdapter@1059fd6] for attribute ‘purchaseController’ because FacesRequestAttributes does not support such callbacks

这个警告消息在我的日志中出现很多.对于每个受管Bean,只要它到期.在给定的时间过后,因为我使用MyFaces乐团.

我已经在我的web.xml中定义了org.springframework.web.context.request.RequestContextListener,而且我的classpath中没有spring jar(即不是类加载问题)

FacesRequestAttribute的文档说:

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.

purchaseController实际上是一个简单的托管bean(不扩展任何只实现Serializable的),用@Controller注释.

UPDATE1:

@Scope(“request”)和@Scope(“session”)中的bean似乎受到影响.
所以我想知道这个警告是否对正确的流量构成任何危险.即如果真的需要这些回调.如果没有,我将跳过与lo4j配置的警告.

更新2:

我进一步挖了一下,似乎这只是有时候发生.如果使用监听器,则RequestContextHolder.currentRequestAttributes()返回ServletRequestAttributes,而不是FacesRequestAttributes.所以看来有时监听器不起作用,并且不会在RequestContextHolder中设置当前的属性.

更新3:

我为RequestContextListener打开了调试,这里是结果:

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

在尝试访问bean之前,请求被破坏.这很奇怪这可能是由于servlet容器实现侦听器处理的一个问题吗?

解决方法

FacesRequestAttributes的javadoc中,我们可以看到:

Note: In contrast to 07001,this variant does not support destruction callbacks for scoped attributes,consider defining a Spring 07002 in your web.xml.

而且,事实上,FacesRequestAttributes的registerDestructionCallback()方法没有做太多的事情:

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

但我的理解是,RequestContextListener(你宣布的)将会照顾这份工作.它的requestDestroyed(ServletRequestEvent requestEvent)方法如下所示:

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

如果你看看ServletRequestAttributes#requestCompleted()的javadoc:

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

所以,我认为你可以安全地跳过WARN与log4j配置(可能通过一点调试会话确认).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读