您可以使用嵌入式Redis,例如https://github.com/kstyrc/embedded-
redis
- 将依赖项添加到pom.xml
调整集成测试的属性,使其指向嵌入式Redis,例如:
spring:
redis:
host: localhost
port: 6379实例化仅在测试中定义的组件中的嵌入式redis服务器:
@Component
public class EmbededRedis {
@Value("${spring.redis.port}")private int redisPort;private RedisServer redisServer;@PostConstructpublic void startRedis() throws IOException { redisServer = new RedisServer(redisPort); redisServer.start();}@PreDestroypublic void stopRedis() { redisServer.stop();}}



