gpt4 book ai didi

java - 无法为类 'org.drools.builder.KnowledgeBuilderFactoryService' 实例化服务

转载 作者:行者123 更新时间:2023-11-29 07:43:00 24 4
gpt4 key购买 nike

我从 Drools 5.5.0 更新到 Drools 6.1.0。

当我执行我的代码时,我遇到了这个问题。

java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:166)
at org.drools.builder.KnowledgeBuilderFactory.loadServiceFactory(KnowledgeBuilderFactory.java:130)
at org.drools.builder.KnowledgeBuilderFactory.getKnowledgeBuilderServiceFactory(KnowledgeBuilderFactory.java:124)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:133)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:119)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:56)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.IllegalArgumentException: Unable to instantiate 'org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl'
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:217)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.call(ServiceRegistryImpl.java:209)
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:164)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:214)
... 10 more
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:126)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:56)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:166)
at org.drools.builder.KnowledgeBuilderFactory.loadServiceFactory(KnowledgeBuilderFactory.java:130)
at org.drools.builder.KnowledgeBuilderFactory.getKnowledgeBuilderServiceFactory(KnowledgeBuilderFactory.java:124)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:133)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:119)
... 3 more
Caused by: java.lang.IllegalArgumentException: Unable to instantiate 'org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl'
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:217)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.call(ServiceRegistryImpl.java:209)
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:164)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:214)
... 10 more

错误所在的第133行是下一个方法中的粗体行:

private static KnowledgeBase readKnowledgeBase() throws Exception {

**KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();**

kbuilder.add(ResourceFactory.newClassPathResource(CTES.RULES),
ResourceType.DRL);

KnowledgeBuilderErrors errors = kbuilder.getErrors();

if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM );

return kbase;
}

我没有更改我的代码的任何行,我不明白它发生了什么:(

谁能帮帮我?

最好的问候!

最佳答案

这是一个根据 6.x 的简单编译和创建 session 。有关更多选项和详细信息,请参阅 javadoc。

import org.kie.api.*;
import org.kie.api.builder.*;
import org.kie.api.runtime.*;

KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
FileInputStream fis = new FileInputStream( CTES.RULES );
kfs.write( "src/main/resources/sale.drl",
ks.getResources().newInputStreamResource( fis ) );
KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( "### errors ###" );
}
KieContainer kieContainer =
ks.newKieContainer( ks.getRepository().getDefaultReleaseId() );

KieBaseConfiguration config = ks.newKieBaseConfiguration();
config.setOption( EventProcessingOption.STREAM );
KieBase kieBase = kieContainer.newKieBase( config );
KieSession kieSession = kieBase.newKieSession();

关于java - 无法为类 'org.drools.builder.KnowledgeBuilderFactoryService' 实例化服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28346857/

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