tomcat+redis实现session
1、网上查找资料,大部分从下面网址下载java代码,因是几年前实现的(大概2,3年前吧),不支持tomcat8https://github.com/jcoleman/tomcat-redis-session-manager
2、在myeclipse 新建一个maven项目【maven-archetype-quickstart】
源文件新建包名com.orangefunction.tomcat.redissessions
讲下载下来的java类拷贝到该包之下(这些java类只实现tomcat7,实现tomcat8需要做一些修改)
JavaSerializer.java
RedisSession.java
RedisSessionHandlerValve.java
RedisSessionManager.java
Serializer.java
SessionSerializationMetadata.java
3、tomcat8与tomcat7 有些实现代码不一样,需各自新建一个maven项目要各自打包,注意tomcat引得版本与jdk要保持一致
====tomcat8 maven pom.xml====
[*]
[*]
[*]org.apache.tomcat
[*]tomcat-catalina
[*]8.0.33
[*]
[*]
[*]redis.clients
[*]jedis
[*]2.7.2
[*]
[*]
[*]
[*]
[*]
[*]
[*]org.apache.maven.plugins
[*]maven-compiler-plugin
[*]3.0
[*]
[*]
[*]1.8
[*]
[*]1.8
[*]
[*]UTF-8
[*]
[*]
[*]
[*]
[*]
====tomcat7 maven pom.xml====
[*]
[*]
[*]
[*]org.apache.tomcat
[*]tomcat-catalina
[*]7.0.27
[*]
[*]
[*]redis.clients
[*]jedis
[*]2.7.2
[*]
[*]
[*]
[*]
[*]
[*]
[*]
[*]org.apache.maven.plugins
[*]maven-compiler-plugin
[*]3.0
[*]
[*]
[*]1.7
[*]
[*]1.7
[*]
[*]UTF-8
[*]
[*]
[*]
[*]
将打包出来的tomcat-redis的jar包和
jedis-2.7.2.jar
commons-pool2-2.3.jar
拷贝到tomcat的lib文件夹下面
4、tomcat配置
====tomcat context.xml====
[*]
[*]
[*]
[*]
[*]host="127.0.0.1"
[*]port="6379"
[*]database="0"
[*]maxInactiveInterval="60" />
[*]
[*]
[*]
[*]
[*]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" />
[*]
[*]
5、需要特别注意的是项目中要存入session的对象必须实现序列化,否知会出现序列化错误
[*]
[*]public>
[*]private static final long serialVersionUID = 5021582410009851677L;
[*]......
[*]}
[*]
配置截图:
转自 https://blog.csdn.net/lzc409973859/article/details/51981079
页:
[1]