From b364c8221f95411af805b2d6c7a85b69ae4ea46f Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Mon, 12 Dec 2022 01:12:16 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I5XUQS=20=E9=85=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=A0=BC=E5=BC=8F=E8=A7=84=E5=88=99=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=8B=A5EL=E8=A7=84=E5=88=99=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8=EF=BC=8C=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E4=BC=9A=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yomahub/liteflow/core/FlowExecutor.java | 6 ++++++ .../spi/spring/SpringPathContentParser.java | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) 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 4055c0db2..2fb35157a 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 @@ -162,6 +162,12 @@ public class FlowExecutor { } } + //如果是ruleSource方式的,最后判断下有没有解析出来,如果没有解析出来则报错 + if (FlowBus.getChainMap().isEmpty()){ + String errMsg = StrUtil.format("no valid rule config found in rule path [{}]", liteflowConfig.getRuleSource()); + throw new ConfigErrorException(errMsg); + } + //执行钩子 if(hook){ FlowInitHook.executeHook(); diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java index c7196f4b2..791f2789e 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.spi.spring; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; @@ -8,6 +9,8 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.spi.PathContentParser; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @@ -18,6 +21,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class SpringPathContentParser implements PathContentParser { @Override @@ -43,16 +47,15 @@ public class SpringPathContentParser implements PathContentParser { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resolver.getResources(locationPattern); - if (ArrayUtil.isEmpty(resources)) { - throw new ConfigErrorException("config error,please check rule source property"); + if (ArrayUtil.isNotEmpty(resources)) { + allResource.addAll(ListUtil.toList(resources)); } - allResource.addAll(ListUtil.toList(resources)); } - //如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 + //检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 Set fileTypeSet = new HashSet<>(); allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getFilename()))); - if (fileTypeSet.size() != 1) { + if (fileTypeSet.size() > 1) { throw new ConfigErrorException("config error,please use the same type of configuration"); }