基于redis的tomcat环境中session共享

1.基于Redis,使用开源解决方案RedisSessionManager解决多Tomcat实例的Session共享问题。

2.复制RedisSessionManager相关Jar包到:<Tomcat安装目录>/lib/下。

需要Tomcat配置文件:<Tomcat安装目录>/conf/context.xml

<?xml version='1.0' encoding='utf-8'?> 
<!-- 
Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with 
this work for additional information regarding copyright ownership. 
The ASF licenses this file to You under the Apache License, Version 2.0 
(the "License"); you may not use this file except in compliance with 
the License. You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0



Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
--> 
<!-- The contents of this file will be loaded for each web application --> 
<Context> 
<WatchedResource>WEB-INF/web.xml</WatchedResource> 
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> 
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" 
host="localhost" 
port="6379" 
database="1" 
maxInactiveInterval="30" /> 
</Context>

//host为Redis的IP地址,Port为Redis的端口,database为Redis的数据库,maxInactiveInterval 为超时时间。 

 

参考资料:

https://github.com/jcoleman/tomcat-redis-session-manager 

猜你喜欢

转载自cairewen.iteye.com/blog/2209230
今日推荐