jfianl项目配置多Tomcat ,Redis session共享时报错

1.报错前配置,云服务器一台,使用Nginx负载两个Tomcat服务(同一IP不同端口8080、8081)。配置两个Tomcat的context.xml前项目正常可访问,配置后添加了Redis做共享的Valve  Manager 后报错,如下


<Valve className="tomcat.request.session.redis.SessionHandlerValve" />


<Manager className="tomcat.request.session.redis.SessionManager" 


host="49.233.153.118" 


port="6379"


password="123456" 


database="0"


maxInactiveInterval="7200" 


/>


希望有解决方案的告知一下,非常感谢


2.报错内容:


[ERROR]-[Thread: http-nio-8081-exec-13]-[com.jfinal.core.ActionHandler.handle()]: com.gftrade.index.IndexController.index() : /


redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool


        at redis.clients.util.Pool.getResource(Pool.java:51)


        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)


        at tomcat.request.session.data.cache.impl.RedisDataCache$RedisCacheUtil.setnx(RedisDataCache.java:271)


        at tomcat.request.session.data.cache.impl.RedisDataCache.setnx(RedisDataCache.java:56)


        at tomcat.request.session.redis.SessionManager.createSession(SessionManager.java:165)


        at tomcat.request.session.redis.SessionManager.createSession(SessionManager.java:37)


        at org.apache.catalina.connector.Request.doGetSession(Request.java:3059)


        at org.apache.catalina.connector.Request.getSession(Request.java:2454)


        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:896)


        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:908)


        at com.jfinal.core.Controller.getSession(Controller.java:460)


        at com.gftrade.common.base.BaseController.render(BaseController.java:414)


        at com.gftrade.index.IndexController.index(IndexController.java:26)


        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)


        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


        at java.lang.reflect.Method.invoke(Method.java:498)


        at com.jfinal.aop.Invocation.invoke(Invocation.java:97)


        at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)


        at com.jfinal.aop.Invocation.invoke(Invocation.java:91)


        at com.jfinal.core.ActionHandler.handle(ActionHandler.java:89)


        at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:89)


        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)


        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)


        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)


        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)


        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)


        at tomcat.request.session.redis.SessionHandlerValve.invoke(SessionHandlerValve.java:37)


        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)


        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)


        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)


        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)


        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)


        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)


        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)


        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)


        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)


        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)


        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)


        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)


        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)


        at java.lang.Thread.run(Thread.java:748)


Caused by: java.util.NoSuchElementException: Unable to validate object


        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:506)


        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericO


评论区

zzutligang

2020-03-04 01:08

这个共享session的redis是你自己写的还是tomcat自带的库?我是自己写了一套,封装了一下实现的。

蓝枫

2020-03-06 19:53

@zzutligang 在GitHub上面下载然后根据网上写的支持Tomcat8的修改方式进行修改,然后在打包成jar放到服务器上的Tomcat里

zzutligang

2020-03-06 23:33

@蓝枫 我是自己写的,借助cookie实现,有兴趣,可以交流一下。

蓝枫

2020-03-13 11:22

已有解决方案,链接:https://pan.baidu.com/s/1yTqv3EoT3mG7lZeL27Xwbw
提取码:lqa3,参考网上资料换了tomcat-cluster-redis-session-manager-3.0.4.jar就可以了。网盘上上传了相应jar以及配置文档可作参考

热门反馈

扫码入社