NoSQL
Spring Boot 提供了多个支持 NoSQL 技术的 starter。 本节解答在 Spring Boot 中使用 NoSQL 时常见的问题。
使用 Jedis 替代 Lettuce
默认情况下,Spring Boot starter(spring-boot-starter-data-redis
)使用 Lettuce。
你需要排除该依赖,并改为引入 Jedis。
Spring Boot 会管理这两种依赖,因此切换到 Jedis 时无需指定版本。
以下示例展示了在 Maven 中如何实现:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
以下示例展示了在 Gradle 中如何实现:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-redis') {
exclude group: 'io.lettuce', module: 'lettuce-core'
}
implementation 'redis.clients:jedis'
// ...
}