【问题标题】:Spring Boot 2 can't connect to RedisSpring Boot 2 无法连接到 Redis
【发布时间】:2018-05-05 17:18:52
【问题描述】:

我正在尝试将 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

我想使用响应式连接,所以我要覆盖 connectionFactory,配置类

@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')
}

谢谢

【问题讨论】:

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


    【解决方案1】:

    对于遇到相同问题的其他人,您需要单独添加生菜依赖项。

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

    仍然没有选择 application.properties 稍后会整理出来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-23
      • 2020-10-26
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 2020-12-23
      • 2020-07-07
      • 2020-07-31
      相关资源
      最近更新 更多