Spring Boot 2无法连接到Redis

我正在尝试使用带有Spring Boot 2和Spring Data Redis的Lettuce驱动程序(最新版本) . 我无法连接到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

我想使用反应连接,所以我重写了connectionFactory,config类

@Configuration
class RedisConfig {

    @Bean
    fun reactiveRedisConnection(redisConnectionFactory: ReactiveRedisConnectionFactory): ReactiveRedisConnection {
        return redisConnectionFactory.reactiveConnection
    }

    @Bean
    fun redisConnectionFactory(): LettuceConnectionFactory {
        return LettuceConnectionFactory()
    }
}

application.properties

## Redis config
spring.redis.host=192.168.99.100
spring.redis.port=32769

的build.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')
}

谢谢

回答(1)

3 years ago

对于遇到同样问题的其他人,你需要分别添加生菜依赖 .

compile("io.lettuce:lettuce-core:5.0.3.RELEASE")

仍然没有选择application.properties将在以后进行排序 .