更新时间:2023-08-22 22:11:04
感谢大家的回复,因为事实证明我犯了几个错误.我根据收到的反馈编辑了问题中的代码.然而,为了解决这个问题,还需要做一件事.
Thank you all for your responses, as it turned out I made several mistakes. I edited the code in my question according to the feedback I received. However there is just one more thing that needed to be done in order to solve this problem.
由于我使用了 UserDetails 的自定义实现,因此我必须覆盖 UserDetailsImpl 类中的 equals 和 hashCode.
Since I use a custom implementation of UserDetails I had to Override equals and hashCode in the UserDetailsImpl class.
@Override
public boolean equals(Object otherUser) {
if(otherUser == null) return false;
else if (!(otherUser instanceof UserDetails)) return false;
else return (otherUser.hashCode() == hashCode());
}
@Override
public int hashCode() {
return user.getEmail().hashCode() ;
}