警告:无法注册销毁回调 [英] WARN: Could not register destruction callback

查看:193
本文介绍了警告:无法注册销毁回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


15:11:14,676 WARN FacesRequestAttributes:121 - 无法为属性'purchaseController'注册销毁回调[org.springframework.beans.factory.support.DisposableBeanAdapter@1059fd6],因为FacesRequestAttributes不支持这样的回调


此警告消息显示在我的日志中很多。对于每个托管bean到期时。它会在给定时间后过期,因为我正在使用MyFaces Orchestra。



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



FacesRequestAttribute的文档说:


注意:与ServletRequestAttributes相比,此变体不支持范围属性的销毁回调,既不支持请求范围也不支持会话范围。如果依赖于此类隐式销毁回调,请考虑在web.xml中定义Spring RequestContextListener。


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



Update1:​​



中的bean @Scope(请求) @Scope( 会话)似乎受到了影响。
所以我想知道这个警告是否对正确的流动造成任何危险。即如果有什么东西真的需要那些回调。如果没有,我将跳过lo4j配置的警告。



更新2:



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



更新3:



我为 RequestContextListener 启用了调试,结果如下:

  07:21:31,518 DEBUG RequestContextListener:69  - 对线程的绑定请求上下文:org.apache.catalina.connector.RequestFacade@1190ae9 
07 :21:31,518 DEBUG RequestContextListener:89 - 清除线程绑定请求上下文:org.apache.catalina.connector.RequestFacade@1190ae9
07:21:31,538 WARN FacesRequestAttributes:121 - 无法注册销毁回调[org.springframework .beans.factory.support.DisposableBeanAdapter @ 11aa152]属性'org.apache.myfaces.orchestra.conversation.AccessScopeManager'因为FacesRequestAttributes不支持这样的回调
07:21:31,541 WARN FacesRequestAttributes:121 - 无法注册破坏回调[org.springframework.bean s.factory.support.DisposableBeanAdapter@1552393]属性'localeController'因为FacesRequestAttributes不支持这样的回调
....等等,其他请求和会话bean

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

解决方案

FacesRequestAttributes ,我们可以阅读:


注意: ServletRequestAttributes ,此变体支持范围属性的销毁回调,既不支持请求范围也不支持会话范围。如果依赖于此类隐式销毁回调,请考虑定义Spring RequestContextListener


实际上 registerDestructionCallback()方法http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/request/FacesRequestAttributes.html\"rel =noreferrer> FacesRequestAttributes 没有做太多事情:

  public void registerDestructionCallback(String name,Runnable callback, int scope){
if(logger.isWarnEnabled()){
logger.warn(无法为属性'+ name +
注册销毁回调[+ callback +] '因为FacesRequestAttributes不支持这样的回调);
}
}

但我的理解是 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){
//我们可能在原始请求线程中...
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 ServletRequestAttributes#requestCompleted()


执行所有请求销毁回调并更新在请求处理期间访问过的会话属性。


所以,我认为你可以安全地跳过带有log4j配置的WARN(虽然可以用一点调试会话来确认)。 / p>

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

This warn message appears in my log a lot. For every managed bean whenever it expires. It expires after a given time, because I'm using MyFaces Orchestra.

I have defined the org.springframework.web.context.request.RequestContextListener in my web.xml, and I don't have the spring jar only ones on my classpath (i.e. not a class-loading problem)

The docs of FacesRequestAttribute says:

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.

The purchaseController is actually a simple managed bean (not extending anything an implementing only Serializable), annotated with @Controller.

Update1:

The beans in @Scope("request") and @Scope("session") seem to be affected. So I wanted to know whether this warn poses any danger to the proper flow. I.e. if something really needs those callbacks. If not, I will just skip the warning with the lo4j config.

Update 2:

I digged a little further, and it seems that this happens only sometimes. IF the listener is used, then RequestContextHolder.currentRequestAttributes() returns the ServletRequestAttributes, rather than FacesRequestAttributes. So it appears that sometimes the listener doesn't work and doesn't set the current attributes in the RequestContextHolder.

Update 3:

I turned debug on for RequestContextListener, and here's 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

It appears that the request gets destroyed before access to the beans is attempted. Which is very odd. Could this be due to a problem in the servlet container implementation of the listener handling?

解决方案

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).

这篇关于警告:无法注册销毁回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆