標籤:tomcat7session redis
1,安裝redis並配置和啟動, tomcat也做相就的下載,其他地方都有,可以在其他地方查閱。
2, 擷取tomcat依賴包:
Tomcat使用 從https://github.com/xetorthio/jedis/downloads下載jedis作為java的redis用戶端,
從https://github.com/jcoleman/tomcat-redis-session-manager/downloads下載tomcat的redis session manager外掛程式
從http://commons.apache.org/proper/commons-pool/download_pool.cgi下載apache的common pool2包,2.2,將這幾個jar包拷貝到tomcat7的lib目錄下
包有: redis2.8、jedis.jar、common-pool2.2.jar、tomcat-redis-session-manager-1.2-tomcat-7.jar
3 配置tomcat
在https://github.com/jcoleman/tomcat-redis-session-manager 這裡面文章看到的配置為:
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="localhost" <!-- optional: defaults to "localhost" -->
port="6379" <!-- optional: defaults to "6379" -->
database="0" <!-- optional: defaults to "0" -->
maxInactiveInterval="60" <!-- optional: defaults to "60" (in seconds) -->
sessionPersistPolicies="PERSIST_POLICY_1,PERSIST_POLICY_2,.." <!-- optional -->
sentinelMaster="SentinelMasterName" <!-- optional -->
sentinels="sentinel-host-1:port,sentinel-host-2:port,.." <!-- optional --> />
而下載的包tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar或tomcat-redis-session-manager-1.2-tomcat-7.jar
裡面並沒有類:com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve
所以從https://github.com/jcoleman/tomcat-redis-session-manager直接下載源碼:
發現源碼裡面存在相應的類,同時源碼(tomcat-redis-session-manager)依賴了tomcat其他的包:tomcat-juli.jar
而tomcat預設是沒有這些包的,從http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.57/bin/extras/ 下載tomcat-juli-adapters.jar和tomcat-juli.jar兩個包,放在apache-tomcat-7.0.57\lib目錄下。
同時將編譯tomcat-redis-session-manager的源碼,通過相應的依賴包common-pool2.2,jedis以及tomcat-juli.jar編譯,並打成自己的jar包,我已經上傳在:
http://download.csdn.net/detail/qinxcb/8279761
然後將這個依賴包放在apache-tomcat-7.0.57\lib目錄下,刪除網上下載的tomcat-redis-session-manager-1.2-tomcat-7.jar.
tomcat7和redis的sessoin共用問題處理