proxy with scope=“request”bean在像servlet或过滤器这样的单例bean中?

rqenqsqc  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(398)

我有一个javax.servlet.filter(因此站点的所有用户共享一个单例),其中aop:scoped-proxy with scope=“request”被注入。
以下是过滤代码:

public class RequestLoggerFilter extends GenericFilterBean {

@Inject
private RequestMonitoringDetail monitoringDetail;

以下是代理bean配置:

<bean id="requestMonitoringDetail" class="com.logging.data.RequestMonitoringDetail" scope="request">
  <aop:scoped-proxy />
</bean>

requestMonitoringDetailbean的作用域是request,因此将为每个请求创建一个新示例,并由注入过滤器的代理使用。我以为它是线程安全的。
问题是在代理上调用方法时,有时会出现get a nullpointerexception:

java.lang.NullPointerException
    at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1555)
    at org.apache.catalina.connector.Request.setAttribute(Request.java:1541)
    at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:540)
    at org.springframework.web.context.request.ServletRequestAttributes.setAttribute(ServletRequestAttributes.java:124)
    at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:44)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:34)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.getTarget(CglibAopProxy.java:665)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:616)
    at com.logging.data.RequestMonitoringDetail$$EnhancerBySpringCGLIB$$6c595aed.getShortLogDetailSuffixesForMonitoring(<generated>)
    at ...

怎么会这样?

c86crjj0

c86crjj01#

我终于找到了原因:tomcat正在关机。就在错误发生之前,有一个关闭的信号:

12-Jan-2021 18:18:11.550 INFOS [RMI TCP Connection(181)-10.109.0.23] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio2-0.0.0.0-8009"]

还不知道它从何而来,但它似乎是错误的原因之后。

相关问题