0

如果子类集合列表中使用了占位符,则无法编译 drools 规则模板。

我有这个简单的类结构

public class Parent {
   private List<Child> children;
}
public class Child {
   private String gender;
}

当使用占位符 @{gender} 时,ExternalSpreadsheetCompiler 会抛出错误 [Error: unclosed @if{} 块。预期的@end{}]

Parent($children: children)
Child(gender == "@{gender}") from $children

在模板中硬编码“MALE”时没有问题

Parent($children: children)
Child(gender == "MALE") from $children

任何想法?谢谢你的帮助。

完整的错误堆栈跟踪:

[Line: 42, Column: 0]
    at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
    at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1291)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:442)
    at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:380)
    at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:136)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:89)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
    at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1341)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1332)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1316)
    at org.drools.template.parser.TemplateDataListener.finishSheet(TemplateDataListener.java:158)
    at org.drools.decisiontable.parser.xls.ExcelParser.finishSheet(ExcelParser.java:277)
    at org.drools.decisiontable.parser.xls.ExcelParser.processSheet(ExcelParser.java:212)
    at org.drools.decisiontable.parser.xls.ExcelParser.parseWorkbook(ExcelParser.java:105)
    at org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:84)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:140)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:168)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:99)
    at org.drools.decisiontable.ExternalSpreadsheetCompiler.compile(ExternalSpreadsheetCompiler.java:85)
    at com.dhl.gssdemo.config.SpringDroolsConfig.addTemplateContent(SpringDroolsConfig.java:112)
    at com.dhl.gssdemo.config.SpringDroolsConfig.classpathDrlKieBase(SpringDroolsConfig.java:102)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.CGLIB$classpathDrlKieBase$0(<generated>)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208$$FastClassBySpringCGLIB$$25a5fef6.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at com.dhl.gssdemo.config.SpringDroolsConfig$$EnhancerBySpringCGLIB$$583d8208.classpathDrlKieBase(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 52 common frames omitted
Caused by: java.lang.RuntimeException: [Error: unclosed @if{} block. expected @end{}]
4

1 回答 1

0

我有同样的问题,我认为它与解析 MVEL 表达式有关,但我通过使用以下解决方法解决了它(使用 $$ 而不是 $)

例如在你的情况下

Parent($children: children) Child(gender == "@{gender}") 来自 $$children

于 2021-04-27T00:42:03.677 回答