项目启动报错redis服务获取不到JedisException: Could not get a resource from the pool

接手问题项目,启动项目报错,redis服务获取不到,修改ip地址端口号用户名密码,连接本地redis服务,仍然打印以下错误

2019-04-04 16:36:41.579 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Failed to register rest://10.10.13.21:9091/cn.rkang.server.usr.service.UsrTestService?anyhost=true&application=rkang-usr-services&dubbo=2.8.3&generic=false&interface=cn.rkang.server.usr.service.UsrTestService&logger=slf4j&methods=getUsrTest&module=usr-single&pid=14116&server=tomcat&side=provider×tamp=1554367001316 to registry localhost:2181, cause: Failed to register service to redis registry. registry: localhost:2181, service: rest://10.10.13.21:9091/cn.rkang.server.usr.service.UsrTestService?anyhost=true&application=rkang-usr-services&dubbo=2.8.3&generic=false&interface=cn.rkang.server.usr.service.UsrTestService&logger=slf4j&methods=getUsrTest&module=usr-single&pid=14116&server=tomcat&side=provider×tamp=1554367001316, cause: Could not get a resource from the pool
    at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:143)
    at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:111)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:53)
    at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:54)
    at com.alibaba.dubbo.rpc.Protocol$Adpative.export(Protocol$Adpative.java)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:489)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:285)
    at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:246)
    at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:145)
    at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:109)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at cn.rkang.server.usr.BootMain.main(BootMain.java:16)
Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to register service to redis registry. registry: localhost:2181, service: rest://10.10.13.21:9091/cn.rkang.server.usr.service.UsrTestService?anyhost=true&application=rkang-usr-services&dubbo=2.8.3&generic=false&interface=cn.rkang.server.usr.service.UsrTestService&logger=slf4j&methods=getUsrTest&module=usr-single&pid=14116&server=tomcat&side=provider×tamp=1554367001316, cause: Could not get a resource from the pool
    at cn.rkang.flame.dubbo.registry.redis.RedisRegistry.doRegister(RedisRegistry.java:279)
    at com.alibaba.dubbo.registry.support.FailbackRegistry.register(FailbackRegistry.java:130)
    ... 21 common frames omitted
Caused by: 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 redis.clients.jedis.JedisPool.getResource(JedisPool.java:16)
    at cn.rkang.flame.dubbo.registry.redis.RedisRegistry.doRegister(RedisRegistry.java:267)
    ... 22 common frames omitted
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(GenericObjectPool.java:363)
    at redis.clients.util.Pool.getResource(Pool.java:49)
    ... 25 common frames omitted

登录redis客户端,手动ping

127.0.0.1:6379> ping
PONG

发现客户端redis服务正常,断点跟进源码发现是JedisFactory中validateObject校验不通过

public boolean validateObject(PooledObject pooledJedis) {
    BinaryJedis jedis = (BinaryJedis)pooledJedis.getObject();

    try {
        HostAndPort hostAndPort = (HostAndPort)this.hostAndPort.get();
        String connectionHost = jedis.getClient().getHost();
        int connectionPort = jedis.getClient().getPort();
        return hostAndPort.getHost().equals(connectionHost) && hostAndPort.getPort() == connectionPort && jedis.isConnected() && jedis.ping().equals("PONG");
    } catch (Exception var6) {
        return false;
    }
}

Alt+F8查看jedis.ping()运行结果,返回异常信息Method threw 'redis.clients.jedis.exceptions.JedisConnectionException' exception.

查看jedis对象中的client属性中的host和port,发现端口号与redis.properties中配置的不同,实际上redis中注入的属性值是dubbo.properties文件中dubbo.registry.address的值。

dubbo.registry.protocol=
dubbo.registry.address=

暂时还不清楚为什么取的不是redis.properties中的port而是dubbo.properties文件中的dubbo.registry.address,稍后有时间会继续探寻

你可能感兴趣的:(工作中遇到的问题)