Java 警告:无法注册销毁回调
15:11:14676警告面请求属性:121-无法注册销毁回调[org.springframework.beans.factory.support]。DisposableBeanAdapter@1059fd6]用于属性“purchaseController”,因为FacesRequestAttribute不支持此类回调 此警告消息经常出现在我的日志中。对于每个托管bean,无论何时过期。它在给定时间后过期,因为我正在使用MyFaces 我已经在我的Java 警告:无法注册销毁回调,java,spring,jsf,orchestra,Java,Spring,Jsf,Orchestra,15:11:14676警告面请求属性:121-无法注册销毁回调[org.springframework.beans.factory.support]。DisposableBeanAdapter@1059fd6]用于属性“purchaseController”,因为FacesRequestAttribute不支持此类回调 此警告消息经常出现在我的日志中。对于每个托管bean,无论何时过期。它在给定时间后过期,因为我正在使用MyFaces 我已经在我的web.xml中定义了org.springfra
web.xml
中定义了org.springframework.web.context.request.RequestContextListener
,并且我的类路径上没有spring jar(也就是说,没有类加载问题)
FacesRequestAttribute的文档说:
注意:与ServletRequestAttributes不同,此变体不支持作用域属性的销毁回调,无论是请求作用域还是会话作用域。如果您依赖于这种隐式的破坏回调,请考虑在Web.xml中定义Spring ReavestCutExtListInter。p>
purchaseController
实际上是一个简单的托管bean(不扩展任何只实现Serializable
),用@Controller
注释
更新1:
@Scope(“请求”)
和@Scope(“会话”)
中的bean似乎受到了影响。
所以我想知道这个警告是否会对正确的流量造成任何危险。也就是说,如果某件事情真的需要这些回调。如果没有,我将跳过lo4j配置的警告
更新2:
我进一步挖掘了一下,似乎这种情况只是偶尔发生。如果使用了侦听器,则RequestContextHolder.currentRequestAttributes()
返回ServletRequestAttributes
,而不是FacesRequestAttribute
。因此,有时侦听器似乎不工作,并且没有在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容器实现中存在问题吗?在的javadoc中,我们可以阅读:
注意:与之相反,此变体不支持作用域属性的销毁回调,无论是请求作用域还是会话作用域。如果您依赖于这种隐式的破坏回调,请考虑在Web.xml中定义一个Spring。p>
事实上,的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");
}
}
但我的理解是(你已经宣布的)将负责这项工作。其requestdestromed(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());
}
}
}
如果你看一下javadoc:
执行所有请求销毁回调并更新在请求处理期间访问的会话属性
因此,我认为您可以安全地使用log4j配置跳过警告(不过可能需要进行一些调试会话来确认这一点)。我尝试添加
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
org.springframework.web.context.request.RequestContextListener
正如二汉14对此的建议
对我来说,这个警告消失了。希望有帮助。有什么问题吗?你想摆脱这些警告吗?或者你想以任何方式注册一个销毁回调?更像是这个回调是否真的需要。因为框架本身正在注册它,而不是我。为了满足我的好奇心,这些注册的
DisposableBeanAdapter
的destroy()
方法中有什么?在我的bean(控制器)中什么都没有。因此,目前这并不是一个失败的问题。但是如果我添加了一个自定义destroy()方法(没有实现DisposableBean),那么在这些情况下恐怕不会调用它。(DisposableBeanAdapter查找并调用自定义销毁方法)感谢,+1所花的时间。我进一步挖掘了一下,似乎这种情况只是偶尔发生。正如你(和我)所引用的,FacesRequestAttributes没有回调。但如果使用了侦听器,则为RequestContextHolder.currentRequestAttributes();返回ServletRequestAttributes,而不是FacesRequestAttribute。因此,有时监听器似乎无法工作..奇怪的是,您提到的方法应该回到当前的JSF FacesContext(如果有的话)。但是我有点胡说八道,今晚我觉得太懒了,无法继续:)是的,通过构造新的FacesContextAttributes(FacesContext.getCurrentInstance()),它确实会回到FacesContext,这就是问题所在——这个对象不注册回调。是什么原因使它退回到它,而不是使用侦听器注册的那个。OP已经这样做了。阅读问题的第二段。谢谢你注意到我的错误。