Tomcat7+redis Session共享



I.准备jar包 两个tomcat



commons-logging-1.1.jar
commons-pool2-2.2.jar
jedis-2.7.3.jar
tomcat-redis-session-manage-tomcat7.jar


http://localhost:8080/dingsai/test.jsp
session.setAttribute("name", "dingsai");
 out.print("name:"+session.getAttribute("name"));
 
 
http://localhost:8888/dingsai/test.jsp
 out.print("name:"+session.getAttribute("name"));






I.配置各个tomcat

在con/content.xml


		<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />   
<!--单点配置-->		
    <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" 
        host="10.1.125.152" 
        port="6379" 
        database="0" 
        maxInactiveInterval="60"/>
<!--多点配置	
<ValveclassName="com.whosenet.tomcat.redissessions.RedisSessionHandlerValve" />
  <ManagerclassName="com.whosenet.tomcat.redissessions.RedisSessionManager"
    maxInactiveInterval="60" sentinelMaster="mymaster"
    sentinels="127.0.0.1:333,127.0.0.1:222,127.0.0.1:333,127.0.0.1:444"/>
-->




复制jar包到
tomcat/lib




I.启动两个tomcat 

访问8080输出:name:dingsai 


再访问8888也输出:name:dingsai 


配置完成


I.遇到问题


 : Begin event threw exception
java.lang.ClassNotFoundException: com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
        at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1288)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
        at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)


升级JDK


jar包下载地址:

http://download.csdn.net/detail/dingsai88/9477139








你可能感兴趣的:(Tomcat7+redis Session共享)