jbpm 使用 Fluent 创建流程 API?
jbpm create process using Fluent API?
根据JBPM关于Fluent的用户指南API,我尝试使用drools的7.62.0版本的FluentAPI创建一个流程,下面是我的示例代码:
public static void testFluentCreateBPMN2() {
String processId = "process1";
ProcessBuilderFactory factory = ProcessBuilderFactories.get();
// Create process builder
Process process = factory.processBuilder(processId)
// package and name
.packageName("org.jbpm")
.name("My process")
// start node
.startNode(1).name("Start").done()
// Add variable of type string
.variable(Variable.var("pepe", String.class))
// Add exception handler
.exceptionHandler(IllegalArgumentException.class, Dialect.JAVA, "System.out.println(\"Exception\");")
// script node in Java language that prints "action"
.actionNode(2).name("Action")
.action(Dialect.JAVA,
"System.out.println(\"Action\");").done()
// end node
.endNode(3).name("End").done()
// connections
.connection(1, 2)
.connection(2, 3)
.build();
KieHelper kieHelper = new KieHelper();
KieSession kieSession = kieHelper.build().newKieSession();
Map<String, Object> maps = new HashMap<>();
maps.put("pepe", "Hello World");
kieSession.startProcess(processId, maps);
}
当我尝试执行此代码时,发生错误,执行 ProcessBuilderFactories.get()
如下:
Exception in thread "main" java.lang.NullPointerException
at org.jbpm.process.core.impl.XmlProcessDumperFactory.newXmlProcessDumperFactory(XmlProcessDumperFactory.java:24)
at org.jbpm.ruleflow.core.RuleFlowProcessFactoryBuilder.<init>(RuleFlowProcessFactoryBuilder.java:26)
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)
at java.lang.Class.newInstance(Class.java:442)
at org.kie.api.fluent.ProcessBuilderFactories.get(ProcessBuilderFactories.java:38)
at org.example.App.testFluentCreateBPMN2(App.java:28)
at org.example.App.main(App.java:23)
我对这个问题感到很困惑。你能给我它的解决方案或一些建议吗?非常感谢。
您的代码中是否包含对 jbpm-bpmn2
或接口 XmlProcessDumperFactoryService
的任何其他实现的依赖项?
jbpm-bpmn2 有这个:
public class XmlProcessDumperFactoryServiceImpl implements XmlProcessDumperFactoryService {
public XmlProcessDumper newXmlProcessDumper() {
return XmlBPMNProcessDumper.INSTANCE;
}
}
根据JBPM关于Fluent的用户指南API,我尝试使用drools的7.62.0版本的FluentAPI创建一个流程,下面是我的示例代码:
public static void testFluentCreateBPMN2() {
String processId = "process1";
ProcessBuilderFactory factory = ProcessBuilderFactories.get();
// Create process builder
Process process = factory.processBuilder(processId)
// package and name
.packageName("org.jbpm")
.name("My process")
// start node
.startNode(1).name("Start").done()
// Add variable of type string
.variable(Variable.var("pepe", String.class))
// Add exception handler
.exceptionHandler(IllegalArgumentException.class, Dialect.JAVA, "System.out.println(\"Exception\");")
// script node in Java language that prints "action"
.actionNode(2).name("Action")
.action(Dialect.JAVA,
"System.out.println(\"Action\");").done()
// end node
.endNode(3).name("End").done()
// connections
.connection(1, 2)
.connection(2, 3)
.build();
KieHelper kieHelper = new KieHelper();
KieSession kieSession = kieHelper.build().newKieSession();
Map<String, Object> maps = new HashMap<>();
maps.put("pepe", "Hello World");
kieSession.startProcess(processId, maps);
}
当我尝试执行此代码时,发生错误,执行 ProcessBuilderFactories.get()
如下:
Exception in thread "main" java.lang.NullPointerException
at org.jbpm.process.core.impl.XmlProcessDumperFactory.newXmlProcessDumperFactory(XmlProcessDumperFactory.java:24)
at org.jbpm.ruleflow.core.RuleFlowProcessFactoryBuilder.<init>(RuleFlowProcessFactoryBuilder.java:26)
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)
at java.lang.Class.newInstance(Class.java:442)
at org.kie.api.fluent.ProcessBuilderFactories.get(ProcessBuilderFactories.java:38)
at org.example.App.testFluentCreateBPMN2(App.java:28)
at org.example.App.main(App.java:23)
我对这个问题感到很困惑。你能给我它的解决方案或一些建议吗?非常感谢。
您的代码中是否包含对 jbpm-bpmn2
或接口 XmlProcessDumperFactoryService
的任何其他实现的依赖项?
jbpm-bpmn2 有这个:
public class XmlProcessDumperFactoryServiceImpl implements XmlProcessDumperFactoryService {
public XmlProcessDumper newXmlProcessDumper() {
return XmlBPMNProcessDumper.INSTANCE;
}
}