Have a simple project with following config
@Configuration@EnableRedisRepositoriespublic class RedisConfig { @Bean public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(connectionFactory); redisTemplate.setHashValueSerializer(new StringRedisSerializer()); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.afterPropertiesSet(); return redisTemplate; }}
application.properties
spring.data.redis.host=localhostspring.data.redis.port=6379
build.gradle for ref
implementation 'org.springframework.boot:spring-boot-starter-data-redis'implementation 'org.springframework.boot:spring-boot-starter-web'testImplementation 'org.springframework.boot:spring-boot-starter-aop'testImplementation 'org.springframework.boot:spring-boot-starter-test'implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'compileOnly 'org.projectlombok:lombok:1.18.20'annotationProcessor 'org.projectlombok:lombok:1.18.20'
The application as such works totally fine, it's able to connect to redis, read/write data. But when I run my JUNITS with the same config, connection keeps failing.
Any idea what might be causing this issue?