在创建bean时获取此错误。
Caused by: java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:162)
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.snapdeal.qualityscore.engine.cache.impl.DroolsRuleBaseCache.getDroolsRuleBase(DroolsRuleBaseCache.java:80)
at com.snapdeal.qualityscore.engine.cache.impl.DroolsRuleBaseCache.populateRuleBase(DroolsRuleBaseCache.java:52)
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.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 27 more
Caused by: java.lang.IllegalArgumentException: Unable to instantiate 'org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl'
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:213)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.call(ServiceRegistryImpl.java:205)
at org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:160)
... 39 more
Caused by: java.lang.ClassNotFoundException: org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:210)
... 41 more
明确指出未找到KnowledgeBuilderFactoryServiceImpl。但是我不明白为什么不是那个班级发现它的内部流氓问题我猜...
无论如何,如果有人可以提供帮助,这里是我的代码吗?
public static KnowledgeBase getDroolsRuleBase(List<InputStream> drlStreams) throws Exception{
KnowledgeBuilder packageBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
KnowledgeBase ruleBase = KnowledgeBaseFactory.newKnowledgeBase();
for (InputStream inputStream : drlStreams)
{
try{
packageBuilder.add(ResourceFactory.newInputStreamResource(inputStream), ResourceType.DRL);
ruleBase.addKnowledgePackages(packageBuilder.getKnowledgePackages());
}
catch(Exception e){
throw new Exception("Rule Base Package Build Failed");
}
}
return ruleBase;
}
答案 0 :(得分:0)
确保项目中存在drools-compiler
依赖项:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.4.0.Final</version>
</dependency>
Drools有时会使用反射来实例化其内部类。这些可以解释您的ClassNotFoundException
。
希望它有所帮助,