Blame view

src/test/java/cn/iocoder/dashboard/config/RedisTestConfiguration.java 1.58 KB
7bb2dd11   YunaiV   引入 redis mock 服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  package cn.iocoder.dashboard.config;
  
  import com.github.fppt.jedismock.RedisServer;
  import org.redisson.spring.starter.RedissonAutoConfiguration;
  import org.springframework.boot.autoconfigure.AutoConfigureBefore;
  import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
  import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
  import org.springframework.boot.context.properties.EnableConfigurationProperties;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Lazy;
  
  import java.io.IOException;
  
  @Configuration
  @Lazy(false) // 禁用懒加载,因为需要保证 Redis Server 必须先启动
  @EnableConfigurationProperties(RedisProperties.class)
  @AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
  public class RedisTestConfiguration {
  
3320f42b   YunaiV   解决 redis 和 mysql ...
21
22
23
24
25
26
27
28
  //    /**
  //     * 创建模拟的 Redis Server 服务器
  //     */
  //    @Bean(initMethod = "start", destroyMethod = "stop")
  //    public RedisServer redisServer(RedisProperties properties) throws IOException {
  //        return new RedisServer(properties.getPort());
  //    }
  
7bb2dd11   YunaiV   引入 redis mock 服务器
29
30
31
      /**
       * 创建模拟的 Redis Server 服务器
       */
3320f42b   YunaiV   解决 redis 和 mysql ...
32
      @Bean(destroyMethod = "stop")
7bb2dd11   YunaiV   引入 redis mock 服务器
33
      public RedisServer redisServer(RedisProperties properties) throws IOException {
3320f42b   YunaiV   解决 redis 和 mysql ...
34
35
36
37
38
          RedisServer redisServer = new RedisServer(properties.getPort());
          try {
              redisServer.start();
          } catch (Exception ignore) {}
          return redisServer;
7bb2dd11   YunaiV   引入 redis mock 服务器
39
40
41
      }
  
  }