gpt4 book ai didi

java - 找不到默认的 KieSession

转载 作者:行者123 更新时间:2023-12-04 14:25:07 29 4
gpt4 key购买 nike

我正在尝试使用 KieModule 创建 jar。请查看代码。

public static ReleaseId createKJarWithMultipleResources(String id, String[] resourceFiles) throws IOException {
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieFileSystem kfs = ks.newKieFileSystem();

for (int i = 0; i < resourceFiles.length; i++) {

kfs.write("src/main/resources/" + id.replaceAll("\\.", "/")
+ "/" + i + ".drl", resourceFiles[i]);
}

KieBaseModel kBase1 = kproj.newKieBaseModel(id)
.setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
.setEventProcessingMode(EventProcessingOption.STREAM);

KieSessionModel ksession1 = kBase1
.newKieSessionModel(id + ".KSession1")
.setType(KieSessionModel.KieSessionType.STATEFUL)
.setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kproj.toXML());

KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( org.kie.api.builder.Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( "### errors ###" );
}
KieModule kieModule = kieBuilder.getKieModule();
return kieModule.getReleaseId();
}

但是当我尝试使用以下代码使用 jar 时:

KieContainer kieContainer =
kieServices.newKieContainer(createKJarWithMultipleResources("1",
new String[]
{new String(Files.readAllBytes(Paths.get("path to drl file")))}
));
KieSession kSession = kieContainer.newKieSession();

出现以下错误:

java.lang.RuntimeException: Cannot find a default KieSession
at org.drools.compiler.kie.builder.impl.KieContainerImpl.findKieSessionModel(KieContainerImpl.java:628)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:621)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:604)
at com.sample.DroolsTest.test2(DroolsTest.java:87)

我错过了什么吗?任何帮助将不胜感激。

最佳答案

问题解决了。我只需要更改代码中的以下几行:

KieSessionModel ksession1 = kBase1
.newKieSessionModel(id + ".KSession1")
.setType(KieSessionModel.KieSessionType.STATEFUL)
.setClockType(ClockTypeOption.get("pseudo"))
.setDefault(true);

注意 setDefault(true),原始代码中没有。

关于java - 找不到默认的 KieSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47528231/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com