如何在springBoot版本1.5.15中配置lettuceConnectionFactory.RELEASE

时间:2018-12-10 11:53:40

标签: spring-boot spring-data-redis lettuce

我试图在Spring Boot项目中使用1.5.15.RELEASE版本配置LettuceConnectionFactory。

这是我的配置文件:

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);



    }

}

我在pom.xml中添加了生菜依赖项

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

启动项目时抛出错误

org.springframework.beans.factory.BeanCreationException:在com.example.redis.RedisApplication中定义的名称为'lettuceConnectionFactory'的bean创建错误:合并后的bean定义的后处理失败;嵌套的异常是java.lang.NoClassDefFoundError:com / lambdaworks / redis / api / StatefulRedisConnection

1 个答案:

答案 0 :(得分:0)

您的依赖性是错误的。

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