我正在尝试将 Lettuce 驱动程序与 Spring Boot 2 和 Spring Data Redis(均为最新版本)结合使用。我无法连接到 Redis,我不断收到以下错误:
Caused by: java.lang.ClassNotFoundException: io.lettuce.core.KeyValue
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
... 148 common frames omitted
我想使用响应式(Reactive)连接,所以我覆盖了 connectionFactory 配置类
@Configuration
class RedisConfig {
@Bean
fun reactiveRedisConnection(redisConnectionFactory: ReactiveRedisConnectionFactory): ReactiveRedisConnection {
return redisConnectionFactory.reactiveConnection
}
@Bean
fun redisConnectionFactory(): LettuceConnectionFactory {
return LettuceConnectionFactory()
}
}
应用程序属性
## Redis config
spring.redis.host=192.168.99.100
spring.redis.port=32769
构建.gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}")
compile('org.springframework.boot:spring-boot-starter-actuator')
compile("org.springframework.data:spring-data-redis")
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.5")
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
谢谢
最佳答案
对于遇到相同问题的其他人,您需要单独添加 lettuce 依赖项。
compile("io.lettuce:lettuce-core:5.0.3.RELEASE")
还没有选择application.properties 稍后再解决。
关于spring-boot - Spring Boot 2 无法连接到 Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50192127/