shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
2016-08-10 23:36
621 查看
在学习Shiro使用缓存时,出现:
java.io.NotSerializableException:org.apache.shiro.util.SimpleByteSource异常,开启debug会提示:
ERROR [authentication.data] - Disk Write of test failed: 错误。
出现这种情况是因为:SimpleByteSource没有是实现Serializable接口
解决办法:自定义一个类继承SimpleByteSource实现Serializable接口
当然也可以实现ByteSource接口和Serializable接口,但是实现ByteSource接口需要实现其方法,不方便。
自定义一个MySimpleByteSource 类继承继承SimpleByteSource实现Serializable接口。
在自定义realm的认证方法中:
java.io.NotSerializableException:org.apache.shiro.util.SimpleByteSource异常,开启debug会提示:
ERROR [authentication.data] - Disk Write of test failed: 错误。
出现这种情况是因为:SimpleByteSource没有是实现Serializable接口
解决办法:自定义一个类继承SimpleByteSource实现Serializable接口
当然也可以实现ByteSource接口和Serializable接口,但是实现ByteSource接口需要实现其方法,不方便。
自定义一个MySimpleByteSource 类继承继承SimpleByteSource实现Serializable接口。
public class MySimpleByteSource extends SimpleByteSource implements Serializable { private static final long serialVersionUID = 1L; public MySimpleByteSource(byte[] bytes) { super(bytes); } }
在自定义realm的认证方法中:
//认证 @Override protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token) throws AuthenticationException { //获得主体对象身份 String username = (String) token.getPrincipal(); //根据用户名查询用户信息 User user = userDao.queryUserByUsername(username); if (user!=null) { return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), new MySimpleByteSource(user.getSalt().getBytes()), getName()); } return null; }
相关文章推荐
- shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- shiro 集成缓存中遇到 java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- storm中使用log出现java.lang.RuntimeException: java.io.NotSerializableException: java.util.logging.Logger
- 使用缓存时出现java.io.NotSerializableException:xxx.xxx.xxx.Bean解决办法
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
- Caused by: java.io.NotSerializableException: org.apache.spark.SparkContext
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException- org.apache.commons.io.IOUtils
- spark1.4 读取hbase 0.96 报错 java.io.NotSerializableException: org.apache.hadoop.hbase.io.ImmutableBytes
- Maven使用tomcat7-maven-plugin插件run时出现错误: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component
- java.io.NotSerializableException: org.hibernate.util.MarkerObject解决办法
- java.io.NotSerializableException: org.apache.log4j.Logger
- 出现java.io.NotSerializableException错误。
- 解决Eclipse中运行WordCount出现 java.lang.ClassNotFoundException: org.apache.hadoop.examples.WordCount$Token
- MAVEN Error: java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
- org.apache.tomcat.util.bcel.classfile.ClassFormatException:it is not a Java .class file
- spark出现task不能序列化错误的解决方法 org.apache.spark.SparkException: Task not serializable
- spark出现“org.apache.spark.SparkException: Task not serializable"
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
- java.io.FileNotFoundException: /mnt/sdcard/yuan.txt (Permission denied) at org.apache.harmony.luni.p
- java.lang.ClassNotFoundException: org.apache.http.util.Args