From eb72d0d0e29dbb6e4432e292ba454c6010adbdc7 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 27 Oct 2023 21:22:10 +0800 Subject: [PATCH] chore: redisson init --- .../main/java/io/metersphere/system/uid/NumGenerator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java index 4cea56a3d0..f9cb4633d9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java @@ -4,6 +4,7 @@ import com.fit2cloud.quartz.anno.QuartzScheduled; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.ApplicationNumScope; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; import org.apache.commons.lang3.StringUtils; import org.redisson.Redisson; @@ -22,8 +23,7 @@ public class NumGenerator { private static StringRedisTemplate stringRedisTemplate; private static ProjectMapper projectMapper; - public NumGenerator(Redisson redisson, StringRedisTemplate stringRedisTemplate, ProjectMapper projectMapper) { - NumGenerator.redisson = redisson; + public NumGenerator(StringRedisTemplate stringRedisTemplate, ProjectMapper projectMapper) { NumGenerator.stringRedisTemplate = stringRedisTemplate; NumGenerator.projectMapper = projectMapper; } @@ -33,6 +33,10 @@ public class NumGenerator { * @param scope 用例类型 */ public static long nextNum(String prefix, ApplicationNumScope scope) { + // 初始化 + if (redisson == null) { + redisson = CommonBeanFactory.getBean(Redisson.class); + } RIdGenerator idGenerator = redisson.getIdGenerator(prefix + "_" + scope.name()); // 每次都尝试初始化,容量为1,只有一个线程可以初始化成功 if (scope.equals(ApplicationNumScope.API_TEST_CASE)) {