当我在kie workbench中创建引导决策表时,我会在执行无状态或有状态kie会话时获得空指针异常。更具体地说,我使用drools 7,并使用java和grizzly公开了一个简单的休息服务。当我使用简单的drl文件时,我的规则正在触发并正确执行,但是当我使用我的jar中的决策表部署时,我得到了NPE。
Java代码:
public CustomerDto executeStatelessPOC(final String param,
final StatelessKieSession kSession ,final KieServices kServices) {
//Myexample is just the entry fact
InputDTO example = new InputDTO();
example.setField1(param);
CustomerDto response = new CustomerDto();
try {
KieCommands kieCommands = kServices.getCommands();
List<Command> cmds = new ArrayList<Command>();
cmds.add(kieCommands.newInsert(example));
cmds.add(kieCommands.newInsert(response, "customerResponse"));
//Execute rules with facts provided before
ExecutionResults results = kSession.execute(kieCommands.newBatchExecution(cmds));
//Get the response as part of the results
response = (CustomerDto) results.getValue("customerResponse");
return response;
} catch (Exception e) {
System.out.println("Exception e: " + e.toString());
System.out.println("Exception e: " + Arrays.toString(e.getStackTrace()));
}
return response;
}
指导决策表的源代码:
package gr.maven.test.testbuildinmaven;
//来自行号:1 规则&#34;第1行TestDecisionTable&#34; 方言&#34; mvel&#34; 什么时候 输入:InputDTO(field1 ==&#34; Test1&#34;) 然后 CustomerDto fact0 = new CustomerDto(); fact0.setCustomerMessage(&#34; yesss&#34;); insertLogical(fact0); 端
//来自行号:2 规则&#34;第2行TestDecisionTable&#34; 方言&#34; mvel&#34; 什么时候 输入:InputDTO(field1 ==&#34; Test2&#34;) 然后 CustomerDto fact0 = new CustomerDto(); fact0.setCustomerMessage(&#34; yes2&#34;); insertLogical(fact0); 端
//来自行号:3 规则&#34;第3行TestDecisionTable&#34; 方言&#34; mvel&#34; 什么时候 输入:InputDTO(field1 ==&#34; Test3&#34;) 然后 CustomerDto fact0 = new CustomerDto(); fact0.setCustomerMessage(&#34; yesss&#34;); insertLogical(fact0); 端
例外:
WARNING: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException堆栈1 of 2 java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129) 在org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:274) 在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:368) at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471) 在org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2064) at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:711) at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:653) 在org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:169) at org.glassfish.jersey.server.model.MethodHandler $ ClassBasedMethodHandler.getInstance(MethodHandler.java:185) 在org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92) 在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61) 在org.glassfish.jersey.process.internal.Stages.process(Stages.java:197) 在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:297) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267) 在org.glassfish.jersey.internal.Errors.process(Errors.java:315) 在org.glassfish.jersey.internal.Errors.process(Errors.java:297) 在org.glassfish.jersey.internal.Errors.process(Errors.java:267) 在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288) 在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110) 在org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:381) 在org.glassfish.grizzly.http.server.HttpHandler $ 1.run(HttpHandler.java:219) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545) 在java.lang.Thread.run(Thread.java:748) 引起:java.lang.NullPointerException at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.guidedDecisionTableToPackageDescr(KnowledgeBuilderImpl.java:411) at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl $ ResourceToPkgDescrMapper.lambda $ static $ 6(CompositeKnowledgeBuilderImpl.java:309) at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildResource(CompositeKnowledgeBuilderImpl.java:187) at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackageDescr(CompositeKnowledgeBuilderImpl.java:176) at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackages(CompositeKnowledgeBuilderImpl.java:109) at org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:99) at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:247) 在org.drools.compiler.kie.builder.impl.AbstractKieModule.createKieBase(AbstractKieModule.java:210) at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:389) 在org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:357) at org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:550) at org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:460) at org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:455) 在com.mycompany.grizzlypoc.rest.services.StatelessService。(StatelessService.java:37) ......还有37个 MultiException堆栈2 of 2 java.lang.IllegalStateException:无法执行操作:在com.mycompany.grizzlypoc.rest.services.StatelessService上创建 在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:395) at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471) 在org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162) at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2064) at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:711) at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:653) 在org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:169) at org.glassfish.jersey.server.model.MethodHandler $ ClassBasedMethodHandler.getInstance(MethodHandler.java:185) 在org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) 在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92) 在org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61) 在org.glassfish.jersey.process.internal.Stages.process(Stages.java:197) 在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:297) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267) 在org.glassfish.jersey.internal.Errors.process(Errors.java:315) 在org.glassfish.jersey.internal.Errors.process(Errors.java:297) 在org.glassfish.jersey.internal.Errors.process(Errors.java:267) 在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288) 在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110) 在org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:381) 在org.glassfish.grizzly.http.server.HttpHandler $ 1.run(HttpHandler.java:219) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565) 在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545) 在java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:2)
在我的POM xml中使用此依赖项解决了问题。
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-workbench-models-guided-dtable</artifactId>
<version>7.7.0.Final</version>
</dependency>
答案 1 :(得分:1)
我很困惑应该更改哪个POM.xml
文件(即规则方或应用方)。
今天我尝试了,得到了答案!它必须与应用程序端。
我的build.gradle如下:
buildscript {
ext {
drools_version = '7.7.0.Final'
}
}
dependencies {
compile "org.drools:drools-workbench-models-guided-dtable:$drools_version"
compile "org.kie:kie-api:$drools_version"
}
我的kotlin项目很好。