Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

How to Connect redis docker container from Spring Boot

$
0
0

i am trying connect to a redis docker container from Spring Boot. After searching in google, I didn't found. Please help me to sort it out.

When i try to connect, it show this error:

Cannot get Jedis connection; nested exception isredis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

enter image description here

enter image description here

<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId></dependency>

//RedisCOnfigurationFIle

@Configuration@EnableCachingpublic class RedisConfig {    @Bean    public JedisConnectionFactory jedisConnectionFactory(){        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();        redisStandaloneConfiguration.setHostName("127.0.0.1");        redisStandaloneConfiguration.setPort(6379);        return new JedisConnectionFactory(redisStandaloneConfiguration);    }    public RedisTemplate<String,Object> redisTemplate(){        RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();        redisTemplate.setConnectionFactory(jedisConnectionFactory());        redisTemplate.setExposeConnection(true);        redisTemplate.setKeySerializer(new StringRedisSerializer());        redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer());        redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());        redisTemplate.setEnableTransactionSupport(true);        redisTemplate.afterPropertiesSet();        return redisTemplate;    }}

//My repositryfile

   @Autowired    private RedisConfig redisConfig;

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>