Java - Google App Engine - 当更改存储在会话作用域中的类时发生InvalidClassException [英] Java - Google App Engine - InvalidClassException when I change a class that was stored in session scope
问题描述
我更新了我的用户类,现在每当有人在其会话范围中存储旧版User类时访问我的网站,我就会得到一个 InvalidClassException
。
javax.servlet.ServletException:java.lang.RuntimeException:
java.io.InvalidClassException:User;本地类不兼容:
stream classdesc serialVersionUID = 4949038118012519093,
本地类serialVersionUID = -971500502189813151
如何阻止这些用户发生这种错误?我可能会在每次想要更新存储在会话范围内的类时都使每个人的会话无效,但是有没有更好的方法,以便我的用户不必再次登录?
private final long serialVersionUID = 4949038118012519093;
添加到您的类定义中。新课程应该具有相同的序列化字段,当然顺序相同。
I updated my User class, and now whenever someone that had the old version of the User class stored in their session scope accesses my site, I get an InvalidClassException
.
javax.servlet.ServletException: java.lang.RuntimeException:
java.io.InvalidClassException: User; local class incompatible:
stream classdesc serialVersionUID = 4949038118012519093,
local class serialVersionUID = -971500502189813151
How do I stop this error from happening for those users? I could probably invalidate everyone's sessions every time I want to update a class that gets stored in session scope, but is there a better way, so that my user's don't have to login again?
You can add
private final long serialVersionUID=4949038118012519093;
to your class definition. New class should have the same serializable fields in the same order of course.
这篇关于Java - Google App Engine - 当更改存储在会话作用域中的类时发生InvalidClassException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!