简体   繁体   English

Tomcat 持久管理器与 JDBC 存储访问 static 资源时抛出空指针异常

[英]Tomcat Persistent Manager with JDBC Store throwing nullpointer exception when accessing static resources

We have been using multiple instances of tomcat (using spring boot) 9.x versions on multiple nodes, which handles static + dynamic resources.我们一直在多个节点上使用 tomcat 的多个实例(使用 spring 引导)9.x 版本,它处理 static + 动态资源。 Intermittently, we have been seeing issues with session management and below given exceptions particularly when multiple static resources like css/js are being accessed from html files.间歇性地,我们看到 session 管理和以下给定异常的问题,特别是当从 ZFC35FDC70D5FC69D269883A822C7A53E 文件访问多个 static 资源(如 css/js)时。

Aug 24 11:51:38 31f8d4f54c9a security [https-jsse-nio-4700-exec-24] 12e42fb1-c0ef-4717-aad9-cc61b5c40929 org.apache.catalina.core.ContainerBase.[Tomcat].[localhost] Exception Processing /security/images/logo.png
java.lang.NullPointerException: null
        at org.apache.catalina.session.StandardSession.doWriteObject(StandardSession.java:1641)
        at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:1065)
        at org.apache.catalina.session.JDBCStore.save(JDBCStore.java:804)
        at org.apache.catalina.valves.PersistentValve.invoke(PersistentValve.java:166)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:829)

From different articles and forums (Reference: Why should Tomcat's PersistentValve not be used where there may be concurrent requests per session? ), it seems that Persistent Valve assumes that only single request is being sent from the session.从不同的文章和论坛(参考: Why should Tomcat's PersistentValve not be used where may there may be concurrent requests per session? ),似乎 Persistent Valve 假设只有一个请求是从 session 发送的。 This is highly unlikely with web applications that requires many css or js files to be rendered on a webpage.对于需要在网页上呈现许多 css 或 js 文件的 web 应用程序,这不太可能发生。

What alternatives exist to manage and externalize this session without using JDBC Store or Persistent Valve?有哪些替代方法可以在不使用 JDBC Store 或 Persistent Valve 的情况下管理和外部化此 session? OR is there any workaround or a way to address this issue?或者是否有任何解决方法或方法来解决这个问题?

Please advise.请指教。

I had the same problem with Tomcat's PersistentValve and I managed to fix it using filter attribute to let Valve know which request really change session values.我对 Tomcat 的 PersistentValve 有同样的问题,我设法使用过滤器属性修复它,让 Valve 知道哪个请求真正改变了 session 值。 Requests for JS, HTML, CSS files or any static resources shouldn't change session so there's no need to change session in database. Requests for JS, HTML, CSS files or any static resources shouldn't change session so there's no need to change session in database. You can find example and description of this Valve here - https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Persistent_Valve您可以在此处找到此阀门的示例和描述 - https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Persistent_Valve

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM