Redis毗连失败(org.springframework.data.redis.connection.PoolException: Could not get a resource from [复制链接]
发表于 2026-4-24 08:55:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
 最开始是这么写的
  1. spring:
  2.   redis:
  3.     database: 1       # 指定所在的库
  4.     host: 127.0.0.1   # Redis服务器地址 写你的ip
  5.     port: 6379        # Redis服务器连接端口
  6.     password: 000000  # Redis服务器连接密码
  7. #    url: redis://000000@127.0.0.1:6379
  8.     lettuce:
  9.       pool:
  10.         max-active: 200   # 连接池最大连接数(使用负值表示没有限制)  类似于mysql的连接池
  11.         max-wait: -1      # 连接池最大阻塞等待时间(使用负值表示没有限制) 表示连接池的链接拿完了 现在去申请需要等待的时间
  12.         max-idle: 10      # 连接池中的最大空闲连接
  13.         min-idle: 0       # 连接池中的最小空闲连接
  14.     timeout: 6000         # 连接超时时间(毫秒) 去链接redis服务端
复制代码
报错
  1. org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379
  2.         at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:87)
  3.         at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1104)
  4.         at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1085)
  5.         at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:866)
  6.         at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:341)
  7.         at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
  8.         at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
  9.         at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82)
  10.         at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:211)
  11.         at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
  12.         at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
  13.         at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
  14.         at com.hhx.redis.TestRedis.getName(TestRedis.java:17)
  15.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  16.         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  17.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  18.         at java.lang.reflect.Method.invoke(Method.java:498)
  19.         at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
  20.         at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
  21.         at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
  22.         at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
  23.         at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
  24.         at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
  25.         at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
  26.         at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
  27.         at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
  28.         at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
  29.         at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
  30.         at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
  31.         at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
  32.         at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
  33.         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
  34.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  35.         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
  36.         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
  37.         at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
  38.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
  39.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  40.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
  41.         at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
  42.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
  43.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  44.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
  45.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
  46.         at java.util.ArrayList.forEach(ArrayList.java:1257)
  47.         at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
  48.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
  49.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  50.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
  51.         at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
  52.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
  53.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  54.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
  55.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
  56.         at java.util.ArrayList.forEach(ArrayList.java:1257)
  57.         at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
  58.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
  59.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  60.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
  61.         at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
  62.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
  63.         at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
  64.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
  65.         at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
  66.         at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
  67.         at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
  68.         at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
  69.         at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
  70.         at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
  71.         at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
  72.         at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
  73.         at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
  74.         at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
  75.         at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
  76.         at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
  77.         at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
  78.         at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
  79.         at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
  80.         at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
  81.         at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
  82.         at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
  83.         at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
  84. Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379
  85.         at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
  86.         at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
  87.         at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:235)
  88.         at io.lettuce.core.RedisClient.connect(RedisClient.java:204)
  89.         at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:113)
  90.         at java.util.Optional.orElseGet(Optional.java:267)
  91.         at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:113)
  92.         at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.lambda$null$0(LettucePoolingConnectionProvider.java:75)
  93.         at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:209)
  94.         at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:199)
  95.         at org.apache.commons.pool2.BasePooledObjectFactory.makeObject(BasePooledObjectFactory.java:58)
  96.         at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:889)
  97.         at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:424)
  98.         at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:349)
  99.         at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:122)
  100.         at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:117)
  101.         at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:81)
  102.         ... 81 more
  103. Caused by: io.lettuce.core.RedisCommandExecutionException: ERR invalid password
  104.         at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135)
  105.         at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108)
  106.         at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
  107.         at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
  108.         at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:646)
  109.         at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:604)
  110.         at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:556)
  111.         at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
  112.         at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
  113.         at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
  114.         at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1421)
  115.         at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
  116.         at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
  117.         at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
  118.         at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
  119.         at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:697)
  120.         at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
  121.         at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
  122.         at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
  123.         at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
  124.         at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
  125.         at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  126.         at java.lang.Thread.run(Thread.java:748)
复制代码
怎么都连不上,看了各种文章,redis设置文件确定了五六遍,redis重启,暗码确定等等,办理了一天这个bug,末了终于找到了办理办法
  1. spring:
  2.   redis:
  3.     database: 1       # 指定所在的库
  4.     host: 127.0.0.1   # Redis服务器地址 写你的ip
  5.     port: 6379        # Redis服务器连接端口
  6. #    password: 000000  # Redis服务器连接密码
  7.     url: redis://000000@127.0.0.1:6379
  8.     lettuce:
  9.       pool:
  10.         max-active: 200   # 连接池最大连接数(使用负值表示没有限制)  类似于mysql的连接池
  11.         max-wait: -1      # 连接池最大阻塞等待时间(使用负值表示没有限制) 表示连接池的链接拿完了 现在去申请需要等待的时间
  12.         max-idle: 10      # 连接池中的最大空闲连接
  13.         min-idle: 0       # 连接池中的最小空闲连接
  14.     timeout: 6000         # 连接超时时间(毫秒) 去链接redis服务端
复制代码
把暗码表明掉,换成URL格式的就好了,又是踩坑的一天。
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表