Camunda bpmn 计时器事件找不到 java 委托

Camunda bpmn timer event cannot find java delegate

我有简单的bpmn流程:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0m0cnse" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
  <bpmn:process id="Process_1aegwvb" isExecutable="true">
    <bpmn:sequenceFlow id="Flow_1dfd8um" sourceRef="StartEvent_1" targetRef="Activity_047mv6x" />
    <bpmn:endEvent id="Event_1vradpp">
      <bpmn:incoming>Flow_19hnbhv</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_19hnbhv" sourceRef="Activity_047mv6x" targetRef="Event_1vradpp" />
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1dfd8um</bpmn:outgoing>
      <bpmn:timerEventDefinition id="TimerEventDefinition_1ah7red">
        <bpmn:timeCycle xsi:type="bpmn:tFormalExpression">0 0/5 * * * ?</bpmn:timeCycle>
      </bpmn:timerEventDefinition>
    </bpmn:startEvent>
    <bpmn:serviceTask id="Activity_047mv6x" name="Get users" camunda:class="*.Cron">
      <bpmn:incoming>Flow_1dfd8um</bpmn:incoming>
      <bpmn:outgoing>Flow_19hnbhv</bpmn:outgoing>
    </bpmn:serviceTask>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1aegwvb">
      <bpmndi:BPMNEdge id="Flow_19hnbhv_di" bpmnElement="Flow_19hnbhv">
        <di:waypoint x="370" y="117" />
        <di:waypoint x="432" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1dfd8um_di" bpmnElement="Flow_1dfd8um">
        <di:waypoint x="215" y="117" />
        <di:waypoint x="270" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Event_1vradpp_di" bpmnElement="Event_1vradpp">
        <dc:Bounds x="432" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_11i5xth_di" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="99" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_01expgb_di" bpmnElement="Activity_047mv6x">
        <dc:Bounds x="270" y="77" width="100" height="80" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
  1. 带有身份验证提供程序的 jar 文件 classes 和 class Cron 添加到文件夹中

camunda/webapps/engine-rest/WEB-INF/lib/ camunda/webapps/camunda/WEB-INF/lib/

如果我在 Camunda Webapp 中或通过 REST API 手动启动此过程,它工作正常并完成必要的工作。但是每隔 5 分钟我就会在日志中看到问题。

  1. 我需要在哪里添加这个 class 到 class 路径?这是一个 docker 图像,具有一些额外的功能、自定义身份验证提供程序等。

  2. Cron.java:

    public class Cron 实现 JavaDelegate {

     @Override
     public void execute(DelegateExecution delegateExecution) {
         System.out.println("Test");
     }
    

    }

    2020 年 9 月 24 日 10:40:05.164 严重 [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16006 BPMN 堆栈跟踪: Activity_047mv6x(activity-执行,ProcessInstance[4ed42252-fe52-11ea-9efd-12baf36f6a87]) Activity_047mv6x, name=获取用户 ^ | StartEvent_1

    2020 年 9 月 24 日 10:40:05.166 SEVERE [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 关闭命令上下文时出现异常:ENGINE-09008 实例化时出现异常 class '.Cron': ENGINE-09017 无法加载 class '.Cron': .Cron org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 实例化 class '.Cron' 时出现异常:ENGINE-09017 无法加载 class '*.Cron': *.Cron 在 org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:81)................................

    原因:java.lang.ClassNotFoundException:*.Cron 在 java.net.URLClassLoader.findClass(URLClassLoader.java:382) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) 在 java.lang.Class.forName0(本机方法) 在 java.lang.Class.forName(Class.java:348) 在 org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:87) ... 还有 92 个

您的流程模型包含实施类型为 Java Class 的用户任务。 Java Class 名称设置为:*.Cron 因此,当您 运行 引擎尝试查找并实例化此名称的 class 进程时。

https://docs.camunda.org/manual/latest/user-guide/process-engine/delegation-code/

To implement a class that can be called during process execution, this class needs to implement the org.camunda.bpm.engine.delegate.JavaDelegate interface and provide the required logic in the execute method. When process execution arrives at this particular step, it will execute this logic defined in that method and leave the activity in the default BPMN 2.0 way.

您需要更改流程模型以引用实际存在的 class (https://docs.camunda.org/manual/latest/reference/bpmn20/tasks/service-task/) 或使用其他实现方法。

您的 Docker 图片可能基于 Camunda BPM 运行。在此发行版中,可以将其他 jar 放在 userlib 文件夹中。 https://docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/ 但是,由于您似乎对 Java 世界并不熟悉,因此您可能需要考虑一种不同的方法来调用您的服务。例如,您可以将服务任务的实现更改为脚本任务或外部服务任务

https://docs.camunda.org/manual/latest/reference/bpmn20/tasks/script-task/

https://docs.camunda.org/manual/latest/reference/bpmn20/tasks/service-task/

通过使用 Cron class 打包创建不同的模块解决了问题 war。 然后将其添加为另一个 Web 应用程序。