shiro 集成缓存中遇到 java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource

来源:互联网 发布:电脑网络参数怎么修改 编辑:程序博客网 时间:2024/06/06 03:59

 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());

      }

0 0
原创粉丝点击