tomcat redis 存放session问题

J2EE 码拜 9年前 (2015-10-12) 1295次浏览
tomcat7.055、redis2.8、jedis.jar、common-pool2.2.jar、tomcat-redissession-manager-1.2-tomcat-7.jar

将上面的3个jar包放入tomcat下的lib目录

修改content.xml

添加:

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
	<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
		host="localhost"
		port="6379" 
		database="0"
		maxInactiveInterval="60"
	/>

启动tomcat时,报错,无法成功启动tomcat。

以下是错误日志:

八月 12, 2014 12:43:16 下午 org.apache.tomcat.util.digester.Digester startElement
严重: Begin event threw error
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool$Config
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2532)
	at java.lang.Class.getConstructor0(Class.java:2842)
	at java.lang.Class.newInstance(Class.java:345)
	at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:145)
	at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1288)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
	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:2786)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
	at org.apache.catalina.startup.ContextConfig.processContextConfig(ContextConfig.java:637)
	at org.apache.catalina.startup.ContextConfig.contextConfig(ContextConfig.java:580)
	at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:837)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:385)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool$Config
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	... 37 more
八月 12, 2014 12:43:16 下午 org.apache.catalina.startup.HostConfig deployDirectory
严重: Error deploying web application directory C:\Apache Software Foundation\tomcat7\tomcat3\apache-tomcat-7.0.55\webapps\docs
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool$Config
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2532)
	at java.lang.Class.getConstructor0(Class.java:2842)
	at java.lang.Class.newInstance(Class.java:345)
	at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:145)
	at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1288)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
	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:2786)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
	at org.apache.catalina.startup.ContextConfig.processContextConfig(ContextConfig.java:637)
	at org.apache.catalina.startup.ContextConfig.contextConfig(ContextConfig.java:580)
	at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:837)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:385)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool$Config
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	... 37 more

在新加入的3个jar包中,均没有需要用到org.apache.commons.pool.impl.GenericObjectPool$Config的地方,redis引用的是

org.apache.commons.pool2.impl.GenericObjectPool$Config,不知道怎么会出现这个错。

在tomcat-redissession-manager-1.2-tomcat-7.jar的源码中有一个类RedisSessionManager在Eclipse中发现有问题。

这个类中有处代码for (Valve valve : getContext().getPipeline().getValves()) 这里的getContext() 方法报错,提示没有该方法,并且在该类的父类ManagerBase中也没有找到该方法。

解决方案:25分
会不会是两个类冲突了

org.apache.commons.pool2.impl.GenericObjectPool$Config

和org.apache.commons.pool.impl.GenericObjectPool$Config

解决方案:50分

问题百度一下打开10个网页, 有7、8个都是完全一样的

解决方案:25分
LZ 本人想问下 你这样做session共享,假如用spring Security 做权限管理 怎么样实现session管理 只允许一个用户登录

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明tomcat redis 存放session问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)