提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.test.config; |
H |
2 |
|
|
3 |
import com.github.fppt.jedismock.RedisServer; |
|
4 |
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; |
|
5 |
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
6 |
import org.springframework.context.annotation.Bean; |
|
7 |
import org.springframework.context.annotation.Configuration; |
|
8 |
import org.springframework.context.annotation.Lazy; |
|
9 |
|
|
10 |
import java.io.IOException; |
|
11 |
|
|
12 |
/** |
|
13 |
* Redis 测试 Configuration,主要实现内嵌 Redis 的启动 |
|
14 |
* |
|
15 |
* @author iailab |
|
16 |
*/ |
|
17 |
@Configuration(proxyBeanMethods = false) |
|
18 |
@Lazy(false) // 禁止延迟加载 |
|
19 |
@EnableConfigurationProperties(RedisProperties.class) |
|
20 |
public class RedisTestConfiguration { |
|
21 |
|
|
22 |
/** |
|
23 |
* 创建模拟的 Redis Server 服务器 |
|
24 |
*/ |
|
25 |
@Bean |
|
26 |
public RedisServer redisServer(RedisProperties properties) throws IOException { |
|
27 |
RedisServer redisServer = new RedisServer(properties.getPort()); |
|
28 |
// 一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样,就导致端口被占用,无法启动。。。 |
|
29 |
try { |
|
30 |
redisServer.start(); |
|
31 |
} catch (Exception ignore) {} |
|
32 |
return redisServer; |
|
33 |
} |
|
34 |
|
|
35 |
} |