我已经通过像许多环节去Jedis,无法获取jedis连接:无法从池中获取资源,并不能得到Jedis连接;
无法从池中获取资源,但仍收到以下错误。
我 在Spring Batch中 使用 Spring Data Redis, 并从mysql读取数据并写入 Redis
DB。似乎有些连接错误。
下面的错误供参考。
2018-07-19 00:08:46 DEBUG o.s.t.support.TransactionTemplate - Initiating transaction rollback on application exception
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:286)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:469)
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
at org.springframework.data.redis.core.RedisConnectionUtils.bindConnection(RedisConnectionUtils.java:70)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:209)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultHashOperations.put(DefaultHashOperations.java:177)
at com.prateek.writer.ProductRedisWriter.write(ProductRedisWriter.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy8.write(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:185)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:284)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:209)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:66)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:308)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:141)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:134)
at com.prateek.App.main(App.java:29)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:276)
... 46 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 49 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 56 common frames omitted
我正在使用以下简单配置。
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"
p:max-total="5"
p:test-on-borrow="true"
p:test-on-return="true"/>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:hostName="10.10.10.10"
p:port="6379"
p:use-pool="true">
<constructor-arg ref="jedisPoolConfig" />
</bean>
<!-- This for KEY -->
<bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="hashKeySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<!-- This is for VALUE -->
<bean id="hashValueSerializer" class="org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer" >
<constructor-arg name="type" value="java.lang.String" />
</bean>
<bean id="valueSerializer" class="org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer" >
<constructor-arg name="type" value="java.lang.String" />
</bean>
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:enableTransactionSupport="true"
p:connection-factory-ref="jedisConnectionFactory"
p:keySerializer-ref="keySerializer"
p:hashKeySerializer-ref="hashKeySerializer"
p:valueSerializer-ref="valueSerializer"
p:hashValueSerializer-ref="hashValueSerializer" />
我在这里发布了答案:无法在10.XX.XX.28:6379处连接到Redis:未知错误-从Spring
Batch或Windows计算机访问时。
解决方案对我来说很好。只是配置没有其他改变。
我需要一些关于我遇到的一些问题的帮助,当尝试连接到redis使用spring Boot。 我正在使用以下重新配置: 和下面的类,我正在尝试创建一个单元测试来测试我的连接: 我知道这里有一个类似的问题,但我还没有要求的分数来评论,我尝试了他们的建议,我仍然得到同样的结果。下面是我的pom.xml: 下面是我的属性文件: redis.clients.jedis.exceptions.jedisconn
Redis.Properties spring-redis.xml 代码 控制器
我正在运行多个工作线程(大约10个)来访问redis Q的数据。 我正在使用infinte timeout For Jedis客户端。 但我仍然收到错误“无法从池中获取资源”。stacktrace如下所示。
大家好,我正在尝试使用Java建立redis服务器。我的Redis服务器是linux服务器,ulimit无限。 这里是创建连接的spring bean 公共类JedisService实现IJedisService,InitializingBean,DisposableBean{private JedisPool JedisPool;
我每5分钟运行一次批处理作业,我不希望其他节点运行同一个作业,因此我使用绝地锁将一个对象锁定5分钟。这样,如果另一个节点试图运行同一个作业,它们就不会得到锁。工作是在获得锁后开始的,当我试图从Redis读取它时,我得到以下异常情况: 这是我的密码 spring启动应用程序。属性文件 作业在开始时执行以下代码以获得锁 之后,redis仓库类试图读取特定模式的值... 这就是我在日志中看到的完全例外。
我成功地获得了20个请求的响应,但无法获得其余10个请求的响应。我面临的问题是,在前20个请求使用了20个连接之后,其余的10个请求无法从池中获得jedis连接,因此我得到以下例外情况: 我已经在网上搜索,但没有找到解决办法。有人能帮我吗?