-1

Have a simple project with following config

@Configuration
@EnableRedisRepositories
public 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=localhost
spring.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?

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71

1 Answers1

0

ufff, after half a day of gruesome trial and error realized this in build.gradle was causing the issue.

testImplementation ('it.ozimov:embedded-redis:0.7.3') {
    exclude module: 'commons-logging'
    exclude module: 'slf4j-simple'
}

I had excluded for brevity sake when wrote the above question here. I would still thank SOF, thank you!

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71