복붙노트

[SPRING] 중첩 예외가 redis.clients.jedis.exceptions.JedisConnectionException : 풀에서 리소스를 가져올 수 없습니다.

SPRING

중첩 예외가 redis.clients.jedis.exceptions.JedisConnectionException : 풀에서 리소스를 가져올 수 없습니다.

나는 이미 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" />

해결법

  1. ==============================

    1.내가 대답을 게시했습니다 : Redis 10.XX.XX.28에 연결할 수 없습니다 : 6379 : 알 수없는 오류 - 스프링 배치 또는 Windows 컴퓨터에서 액세스하는 동안.

    내가 대답을 게시했습니다 : Redis 10.XX.XX.28에 연결할 수 없습니다 : 6379 : 알 수없는 오류 - 스프링 배치 또는 Windows 컴퓨터에서 액세스하는 동안.

    솔루션은 나를 위해 잘 작동합니다. 그것은 단지 config 변경 사항입니다.

  2. ==============================

    2.Azure Redis Cache 구성에서 'SSL을 통한 액세스 만 허용'이 활성화 된 경우 (예 : 포트 번호 6380에 SSL을 사용하고 비 SSL 포트 번호를 6379로 비활성화 한 경우) spring.redis.ssl = true 속성을 다음과 같이 설정하십시오. 귀하의 프로젝트.

    Azure Redis Cache 구성에서 'SSL을 통한 액세스 만 허용'이 활성화 된 경우 (예 : 포트 번호 6380에 SSL을 사용하고 비 SSL 포트 번호를 6379로 비활성화 한 경우) spring.redis.ssl = true 속성을 다음과 같이 설정하십시오. 귀하의 프로젝트.

  3. from https://stackoverflow.com/questions/51408969/nested-exception-is-redis-clients-jedis-exceptions-jedisconnectionexception-cou by cc-by-sa and MIT license