From 4f89b49e5af0361372287dbe2935ab6dba016fac Mon Sep 17 00:00:00 2001 From: lzh Date: Fri, 24 Apr 2026 14:35:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(iot):=20B7=20BranchNode=20@Lazy=20=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=20NodeProviderRegistry=20=E6=89=93=E7=A0=B4=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 启动失败:Spring 检测到环形依赖 nodeProviderRegistry → branchNode → nodeProviderRegistry 根因:BranchNode 既是 NodeProvider(被 Registry 收集),又依赖 Registry dispatch 子节点 — 典型 "collect vs dispatch" 死结。 修复:构造参数加 @Lazy,Spring 注入代理,首次方法调用才解析 Registry, 构造阶段打破环。运行期行为等价。 rule 模块 177/177 测试全绿。 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../com/viewsh/module/iot/rule/engine/branch/BranchNode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/viewsh-module-iot/viewsh-module-iot-rule/src/main/java/com/viewsh/module/iot/rule/engine/branch/BranchNode.java b/viewsh-module-iot/viewsh-module-iot-rule/src/main/java/com/viewsh/module/iot/rule/engine/branch/BranchNode.java index f0a3d734..522d0346 100644 --- a/viewsh-module-iot/viewsh-module-iot-rule/src/main/java/com/viewsh/module/iot/rule/engine/branch/BranchNode.java +++ b/viewsh-module-iot/viewsh-module-iot-rule/src/main/java/com/viewsh/module/iot/rule/engine/branch/BranchNode.java @@ -10,6 +10,7 @@ import com.viewsh.module.iot.rule.engine.NodeProviderRegistry; import com.viewsh.module.iot.rule.engine.NodeResult; import com.viewsh.module.iot.rule.engine.RuleContext; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import java.util.List; @@ -52,7 +53,7 @@ public class BranchNode implements NodeProvider { private final BranchExecutor branchExecutor; public BranchNode(ConditionEvaluatorManager conditionEvaluatorManager, - NodeProviderRegistry nodeProviderRegistry) { + @Lazy NodeProviderRegistry nodeProviderRegistry) { this.conditionEvaluatorManager = conditionEvaluatorManager; this.nodeProviderRegistry = nodeProviderRegistry; this.branchExecutor = new BranchExecutor(conditionEvaluatorManager);