【发布时间】:2018-12-10 11:53:40
【问题描述】:
我试图在 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
【问题讨论】:
标签: spring-boot spring-data-redis lettuce