今天用memcached在集成到java项目之后出现了问题:(运维已经搭好了服务)
场景:用其中一台服务器访问,登陆成功之后,关闭这台服务器,之后登陆另一台服务器,不能把user信息共享过去。
环境:序列化策略用的是java的Serializable,两台服务器均为jdk1.7,tomcat6.
没有任何作用的思路:查看日志,发现是序列化失败,刚开始以为在需要序列化的实体类UserInfo里引入有HibernateTemplate,以为是他引起的不能序列化,从而注掉了所有的ht相关的代码,两台服务器都重启之后发现还是这样的错误。
以下是Catalina.out错误日志:
WARNING: Caught IOException decoding 27457 bytes of data
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.springframework.orm.hibernate3.HibernateTemplate
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at de.javakaffee.web.msm.JavaSerializationTranscoder.deserializeAttributes(JavaSerializationTranscoder.java:167)
at de.javakaffee.web.msm.TranscoderService.deserializeAttributes(TranscoderService.java:156)
at de.javakaffee.web.msm.TranscoderService.deserialize(TranscoderService.java:113)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.loadFromMemcached(MemcachedBackupSessionManager.java:713)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.findSession(MemcachedBackupSessionManager.java:465)
at org.apache.catalina.connector.Request.doGetSession(Request.java:2419)
at org.apache.catalina.connector.Request.getSessionInternal(Request.java:2343)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:431)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.NotSerializableException: org.springframework.orm.hibernate3.HibernateTemplate
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at de.javakaffee.web.msm.JavaSerializationTranscoder.writeAttributes(JavaSerializationTranscoder.java:133)
at de.javakaffee.web.msm.JavaSerializationTranscoder.serializeAttributes(JavaSerializationTranscoder.java:96)
at de.javakaffee.web.msm.TranscoderService.serializeAttributes(TranscoderService.java:140)
at de.javakaffee.web.msm.BackupSessionTask.serializeAttributes(BackupSessionTask.java:150)
at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:101)
at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:38)
at de.javakaffee.web.msm.BackupSessionService$SynchronousExecutorService.submit(BackupSessionService.java:324)
at de.javakaffee.web.msm.BackupSessionService.backupSession(BackupSessionService.java:195)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.backupSession(MemcachedBackupSessionManager.java:670)
at de.javakaffee.web.msm.SessionTrackerValve.backupSession(SessionTrackerValve.java:157)
at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:92)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
... 8 more
Jul 27, 2016 1:47:33 PM de.javakaffee.web.msm.MemcachedBackupSessionManager loadFromMemcached
WARNING: Could not load session with id 873C8F18B59C5D6D1C76608CA8D3CFD4-n1 from memcached.
java.lang.RuntimeException: Caught IOException decoding data
at de.javakaffee.web.msm.JavaSerializationTranscoder.deserializeAttributes(JavaSerializationTranscoder.java:183)
at de.javakaffee.web.msm.TranscoderService.deserializeAttributes(TranscoderService.java:156)
at de.javakaffee.web.msm.TranscoderService.deserialize(TranscoderService.java:113)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.loadFromMemcached(MemcachedBackupSessionManager.java:713)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.findSession(MemcachedBackupSessionManager.java:465)
at org.apache.catalina.connector.Request.doGetSession(Request.java:2419)
at org.apache.catalina.connector.Request.getSessionInternal(Request.java:2343)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:431)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.springframework.orm.hibernate3.HibernateTemplate
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at de.javakaffee.web.msm.JavaSerializationTranscoder.deserializeAttributes(JavaSerializationTranscoder.java:167)
... 15 more
Caused by: java.io.NotSerializableException: org.springframework.orm.hibernate3.HibernateTemplate
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at de.javakaffee.web.msm.JavaSerializationTranscoder.writeAttributes(JavaSerializationTranscoder.java:133)
at de.javakaffee.web.msm.JavaSerializationTranscoder.serializeAttributes(JavaSerializationTranscoder.java:96)
at de.javakaffee.web.msm.TranscoderService.serializeAttributes(TranscoderService.java:140)
at de.javakaffee.web.msm.BackupSessionTask.serializeAttributes(BackupSessionTask.java:150)
at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:101)
at de.javakaffee.web.msm.BackupSessionTask.call(BackupSessionTask.java:38)
at de.javakaffee.web.msm.BackupSessionService$SynchronousExecutorService.submit(BackupSessionService.java:324)
at de.javakaffee.web.msm.BackupSessionService.backupSession(BackupSessionService.java:195)
at de.javakaffee.web.msm.MemcachedBackupSessionManager.backupSession(MemcachedBackupSessionManager.java:670)
at de.javakaffee.web.msm.SessionTrackerValve.backupSession(SessionTrackerValve.java:157)
at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:92)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
... 8 more
之前没做过类似的东西,求解析。
最后结论为jar包原因:
引入了memcached-session-manager,后来加上了一个memcached-session-manager-tc6,纠错的时候应该抱着不要相信任何人的态度,我不应该只不相信自己。
http://www.oschina.net/news/75510/bboss-session-5-0-1
bbosssession,最好的session共享框架。跨容器,带监控,配置简洁灵活,可以使用redis和mongodb来存储会话数据。
memcached做session虽然有他的不足,不过是考虑到实际项目后的选择,还是多谢你请问我项目中也有这个问题,是不是多了jar包,报的是不能序列化的异常。版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。