0

I was trying to configure LettuceConnectionFactory in spring boot project with 1.5.15.RELEASE version.

This is my configuration file:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

@SpringBootApplication
public class RedisApplication {

  private static final Logger LOGGER = LoggerFactory.getLogger(RedisApplication.class);

  @Bean
  public LettuceConnectionFactory lettuceConnectionFactory()
   {
      LOGGER.info("Setup lettuce config");
      final LettuceConnectionFactory factory = new LettuceConnectionFactory();
      return factory;
  }

  @Bean
  RedisTemplate<String,User> redisTemplate()
  {
    RedisTemplate<String,User> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(lettuceConnectionFactory());
    return redisTemplate;
  }

    public static void main(String[] args) {

        SpringApplication.run(RedisApplication.class, args);



    }

}

I added the lettuce dependency in pom.xml

<dependency>
            <groupId>biz.paluch.redis</groupId>
            <artifactId>lettuce</artifactId>
            <version>3.5.0.Final</version>
        </dependency>

while starting project it was throwing error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lettuceConnectionFactory' defined in com.example.redis.RedisApplication: Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: com/lambdaworks/redis/api/StatefulRedisConnection

Noa Even
  • 137
  • 1
  • 10
Balaji S
  • 1
  • 1
  • 2

1 Answers1

0

Your dependency is wrong.

Try <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>${lettuce.version}</version> </dependency>

Jacques Koorts
  • 1,819
  • 1
  • 17
  • 10