java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
是由于 SimpleByteSource 没有实现序列化接口导致。
在集成redis缓存, 开启缓存认证时候报错
<!-- 启用认证缓存,当用户登录一次后将不在查询数据库来获取用户信息,直接在从缓存获取 -->
<property name="authenticationCachingEnabled" value="true" />
我的解决方案 写一个新类去继承SimpleByteSource,并实现序列化接口
public class MySimpleByteSource extends SimpleByteSource implements Serializable {
public MySimpleByteSource(byte[] bytes) {
super(bytes);
// TODO Auto-generated constructor stub
}
}
在处理认证中
protected AuthenticationInfo doGetAuthenticationInfo(
AuthenticationToken token) throws AuthenticationException {
return new SimpleAuthenticationInfo(model, user.getPassword(), new MySimpleByteSource(salt), getName());
}