最近因为jedis 2.1.0接口的一些问题,升级版本了版本,结果出现了一个诡异的问题;时常能正常启动,时常出现jedisPool初始化时 java.lang.IllegalArgumentException: hostname can’t be null
原因出在spring JedisPool构造参数上,之前spring的配置如下
明显是因为host没有注入,但时常又可以,诡异!!!之后弄了jedis源码,加了日志,才定位到原因,查看JedisPool源码,其中的两构造函数如下
public JedisPool(final GenericObjectPoolConfig poolConfig, final String host, final int port) { this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null); } public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri, final int timeout) { super(poolConfig, new JedisFactory(uri.getHost(), uri.getPort(), timeout, JedisURIHelper.getPassword(uri), JedisURIHelper.getDBIndex(uri) != null ? JedisURIHelper.getDBIndex(uri) : 0, null)); }
我们调用的是第一个构造函数,但事实是可能会调用第二个构造函数;port当做了timeout,host当做了URI。
不是很明白spring为什么会把value是字符串的参数匹配到URI上,那就明确指定类型吧
jedis之前的异常为,方面遇到同问题的同学
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:50) at redis.clients.jedis.JedisPool.getResource(JedisPool.java:88) at com.renhenet.modules.redis.RedisService.getHash(RedisService.java:364) at com.renhenet.modules.member.MemberRedisService.getMemberIndustryByMemberId(MemberRedisService.java:240) at com.renhenet.modules.member.MemberService.getMemberIndustry(MemberService.java:236) at com.renhenet.modules.member.MemberService$$FastClassByCGLIB$$b34212a.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) at com.renhenet.modules.member.MemberService$$EnhancerByCGLIB$$1638ea72.getMemberIndustry( ) at com.renhenet.fw.struts2.interceptor.LoginRenheInterceptor.intercept(LoginRenheInterceptor.java:68) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.renhenet.fw.struts2.interceptor.WebRenheInterceptor.intercept(WebRenheInterceptor.java:27) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) at com.renhenet.fw.struts2.filter.RenheStruts2Filter.doFilter(RenheStruts2Filter.java:32) at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:265) at com.caucho.server.hmux.HmuxRequest.handleRequest(HmuxRequest.java:436) at com.caucho.server.port.TcpConnection.run(TcpConnection.java:682) at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:730) at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:649) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: hostname can't be null at java.net.InetSocketAddress.checkHost(InetSocketAddress.java:149) at java.net.InetSocketAddress. (InetSocketAddress.java:216) at redis.clients.jedis.Connection.connect(Connection.java:142) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:75) at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1572) at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:69)
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级