tomcat7用redis存储session报错 5
com.orangefunction.tomcat.redissessions.RedisSessionManagersessionFromSerializedDataS...
com.orangefunction.tomcat.redissessions.RedisSessionManager sessionFromSerializedDataSEVERE: Unable to deserialize into sessionjava.lang.ClassNotFoundException:
展开
2个回答
展开全部
其实很简单,就几个步骤:
1.配置Tomcat的conf目录下的context.xml文件:
1> 单点Reids配置
<!--
Jedis save session
-->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"/>123456789123456789
2> Sentinel集群配置:
<!-- Sentinel 配置 -->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
maxInactiveInterval="60"
sentinelMaster="mymaster"
sentinels="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382"
/>12345671234567
2.添加jar
3.测试
1>
存储Session:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hello");
//取得Session对象
HttpSession session=request.getSession();
//设置Session属性
for(int i=0;i<100000;i++){
session.setAttribute("name"+i, "Magci_"+i);
}
}123456789123456789
2>重启Tomcat:假如Session保存在tomcat下,重启后Session不存在;如果保存在Redis下,Tomcat重启对Session无影响
3>取出Session:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hello");
//取得Session对象
HttpSession session=request.getSession();
//取出Session属性
for(int i=0;i<100000;i++){
System.out.println(session.getAttribute("name"+i));
}
}123456789123456789
注意事项:从Tomcat6开始默认开启了Session持久化设置,测试时可以关闭本地Session持久化,其实也很简单,在Tomcat的conf目录下的context.xml文件中,取消注释下面那段配置即可:
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->12341234
详见这篇博客:Session持久化的实例分析
可以尝试运行上面的demo案例!
1.配置Tomcat的conf目录下的context.xml文件:
1> 单点Reids配置
<!--
Jedis save session
-->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"/>123456789123456789
2> Sentinel集群配置:
<!-- Sentinel 配置 -->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
maxInactiveInterval="60"
sentinelMaster="mymaster"
sentinels="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382"
/>12345671234567
2.添加jar
3.测试
1>
存储Session:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hello");
//取得Session对象
HttpSession session=request.getSession();
//设置Session属性
for(int i=0;i<100000;i++){
session.setAttribute("name"+i, "Magci_"+i);
}
}123456789123456789
2>重启Tomcat:假如Session保存在tomcat下,重启后Session不存在;如果保存在Redis下,Tomcat重启对Session无影响
3>取出Session:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hello");
//取得Session对象
HttpSession session=request.getSession();
//取出Session属性
for(int i=0;i<100000;i++){
System.out.println(session.getAttribute("name"+i));
}
}123456789123456789
注意事项:从Tomcat6开始默认开启了Session持久化设置,测试时可以关闭本地Session持久化,其实也很简单,在Tomcat的conf目录下的context.xml文件中,取消注释下面那段配置即可:
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->12341234
详见这篇博客:Session持久化的实例分析
可以尝试运行上面的demo案例!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询