Tomcat 拋出 Cannot serialize session attribute 異常

來源:互聯網
上載者:User

今天team成員遇到個很奇怪的問題,在啟動和關閉Tomcat 6時, 拋出如下異常:Cannot serialize session attribute XXX  for 。我很是納悶,到apache官網查看了下,發現tomcat 會試圖 serialize存在的session資源. 如果 sessions中相關的對象沒有實現 serializable 介面, 就會出現Cannot serialize session attribute XXX  for  異常。由於開始對某個類實現了Serializable介面,啟動了tomcat,然後又取消實現Serializable介面,重啟tomcat就報錯了。原文如下:

Because when you shutdown tomcat, it tries to serial all objects within
the session scope.  The
class you are referring to
'org.apache.commons.fileupload.DeferredFileOutputStream' does not
implement 'java.io.Serializable' and therefore tomcat throws this
exception when trying to serialize it.

Whilst I don't know what the class
'org.apache.catalina.session.StandardManager' does, presumably is
performs a check to see if an object stored within the session is
serializable before trying to
write it disk, or it might remove non-serializable object from the
session scope on shutdown.

如果你不想看到該異常, 也不想儲存session. 那麼你可以在項目部署描述檔案中(如. test.xml,)(instead of just exploding the war)  的  <Context> tags中間 加上 :

<Manager className="org.apache.catalina.session.PersistentManager"saveOnRestart="false"/>

這樣 tomcat 在關閉的時候就不會儲存session資源了.你也可以在server.xml中指定上面的值. 這也所有的程式都使用這個設定了.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.