diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java index 02fa64608..9c7178dd5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowConditionBuilder.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.builder; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.entity.flow.Chain; import com.yomahub.liteflow.entity.flow.Condition; import com.yomahub.liteflow.entity.flow.Node; @@ -10,6 +11,7 @@ import com.yomahub.liteflow.exception.ExecutableItemNotFoundException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.parser.RegexEntity; import com.yomahub.liteflow.parser.RegexNodeEntity; +import com.yomahub.liteflow.util.SpringAware; import java.util.ArrayList; @@ -85,6 +87,13 @@ public class LiteFlowConditionBuilder { Chain chain = FlowBus.getChain(item.getId()); this.condition.getNodeList().add(chain); } else { + //元数据没有的话,从spring上下文再取一遍,这部分是为了防止标有@Lazy懒加载的组件 + NodeComponent nodeComponent = SpringAware.getBean(item.getId()); + if (ObjectUtil.isNotNull(nodeComponent)){ + FlowBus.addSpringScanNode(item.getId(), nodeComponent); + return setValue(value); + } + String errorMsg = StrUtil.format("executable node[{}] is not found!", regexEntity.getItem().getId()); throw new ExecutableItemNotFoundException(errorMsg); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 03cbe1a08..d4fbff396 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -408,5 +408,4 @@ public class FlowExecutor { public void setLiteflowConfig(LiteflowConfig liteflowConfig) { this.liteflowConfig = liteflowConfig; } - -} +} \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java new file mode 100644 index 000000000..a1e472e63 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.lazy; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ZipUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"}) +public class LazySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java new file mode 100644 index 000000000..9d3dacbca --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 000000000..13bfe6725 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 000000000..3f45e86a6 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/lazy/application.properties b/liteflow-testcase-springboot/src/test/resources/lazy/application.properties new file mode 100644 index 000000000..372a320c8 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/lazy/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lazy/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml b/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/lazy/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file