解决 redis 和 mysql 在单元测试会报错的问题

This commit is contained in:
YunaiV
2021-03-01 00:21:39 +08:00
parent 7bb2dd1167
commit 3320f42bd7
3 changed files with 23 additions and 11 deletions

View File

@ -18,12 +18,24 @@ import java.io.IOException;
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
public class RedisTestConfiguration {
// /**
// * 创建模拟的 Redis Server 服务器
// */
// @Bean(initMethod = "start", destroyMethod = "stop")
// public RedisServer redisServer(RedisProperties properties) throws IOException {
// return new RedisServer(properties.getPort());
// }
/**
* 创建模拟的 Redis Server 服务器
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@Bean(destroyMethod = "stop")
public RedisServer redisServer(RedisProperties properties) throws IOException {
return new RedisServer(properties.getPort());
RedisServer redisServer = new RedisServer(properties.getPort());
try {
redisServer.start();
} catch (Exception ignore) {}
return redisServer;
}
}