在github上已经有人实现该功能,but 在tomcat8下不可用. 所以只能fork自己动手了.其实主要不兼容的问题是一个强制类型转换的事.
com.orangefunction.tomcat.redissessions.RedisSessionManager#initializeSerializer if (getContainer() != null) { loader = ((Context)getContainer()).getLoader(); }
使用:
1. 将jar放到 $Catalina_Home$/lib 目录下.
-- tomcat8-redis-session-manager // [email protected]:fly0wing/tomcat-redis-session-manager.git
-- redis.clients:jedis:2.5.1
-- org.apache.commons:commons-pool2:2.2
2. 添加 context.xml 文件到web项目的webapp/Meta-Inf/文件夹下.
<?xml version='1.0' encoding='utf-8'?> <Context useHttpOnly="true" sessionCookiePath="/"> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.2.100" port="7777" database="0" maxInactiveInterval="60"/> </Context>