java – WARN:无法注册销毁回调
这个警告消息在我的日志中出现很多.对于每个受管Bean,只要它到期.在给定的时间过后,因为我使用MyFaces乐团. 我已经在我的web.xml中定义了org.springframework.web.context.request.RequestContextListener,而且我的classpath中没有spring jar(即不是类加载问题) FacesRequestAttribute的文档说:
purchaseController实际上是一个简单的托管bean(不扩展任何只实现Serializable的),用@Controller注释. UPDATE1: @Scope(“request”)和@Scope(“session”)中的bean似乎受到影响. 更新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中,我们可以看到:
而且,事实上, 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"); } } 但我的理解是, 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()); } } } 如果你看看
所以,我认为你可以安全地跳过WARN与log4j配置(可能通过一点调试会话确认). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |