Camunda BPMN 定时事件无法找到 Java 代理

huangapple go评论95阅读模式
英文:

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. 将具有认证提供程序类和类Cron的JAR文件添加到以下文件夹中:

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

    如果我在Camunda Webapp中手动启动此流程或通过REST API启动它,它可以正常工作并执行必要的任务。但是每隔5分钟,我在日志中看到问题。

  2. 我应该在哪里将这个类添加到类路径中?这是一个带有一些额外功能、自定义认证提供程序等的Docker镜像。

  3. Cron.java:

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

    2020年9月24日 10:40:05.164 SEVERE [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16006 BPMN堆栈跟踪:

    Activity_047mv6x(activity-execute,ProcessInstance[4ed42252-fe52-11ea-9efd-12baf36f6a87])

    Activity_047mv6x,名称=Get users
    ^
    |
    StartEvent_1

    2020年9月24日 10:40:05.166 SEVERE [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 关闭命令上下文时出现异常:ENGINE-09008 实例化类'.Cron'时出现异常:ENGINE-09017 无法加载类'.Cron':*.Cron

    org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 实例化类'.Cron'时出现异常:ENGINE-09017 无法加载类'.Cron':*.Cron
    at org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:81).............

    引起原因:java.lang.ClassNotFoundException: *.Cron
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass

英文:

I have simple bpmn process:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;bpmn:definitions xmlns:bpmn=&quot;http://www.omg.org/spec/BPMN/20100524/MODEL&quot; xmlns:bpmndi=&quot;http://www.omg.org/spec/BPMN/20100524/DI&quot; xmlns:dc=&quot;http://www.omg.org/spec/DD/20100524/DC&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:camunda=&quot;http://camunda.org/schema/1.0/bpmn&quot; xmlns:di=&quot;http://www.omg.org/spec/DD/20100524/DI&quot; id=&quot;Definitions_0m0cnse&quot; targetNamespace=&quot;http://bpmn.io/schema/bpmn&quot; exporter=&quot;Camunda Modeler&quot; exporterVersion=&quot;4.2.0&quot;&gt;
  &lt;bpmn:process id=&quot;Process_1aegwvb&quot; isExecutable=&quot;true&quot;&gt;
    &lt;bpmn:sequenceFlow id=&quot;Flow_1dfd8um&quot; sourceRef=&quot;StartEvent_1&quot; targetRef=&quot;Activity_047mv6x&quot; /&gt;
    &lt;bpmn:endEvent id=&quot;Event_1vradpp&quot;&gt;
      &lt;bpmn:incoming&gt;Flow_19hnbhv&lt;/bpmn:incoming&gt;
    &lt;/bpmn:endEvent&gt;
    &lt;bpmn:sequenceFlow id=&quot;Flow_19hnbhv&quot; sourceRef=&quot;Activity_047mv6x&quot; targetRef=&quot;Event_1vradpp&quot; /&gt;
    &lt;bpmn:startEvent id=&quot;StartEvent_1&quot;&gt;
      &lt;bpmn:outgoing&gt;Flow_1dfd8um&lt;/bpmn:outgoing&gt;
      &lt;bpmn:timerEventDefinition id=&quot;TimerEventDefinition_1ah7red&quot;&gt;
        &lt;bpmn:timeCycle xsi:type=&quot;bpmn:tFormalExpression&quot;&gt;0 0/5 * * * ?&lt;/bpmn:timeCycle&gt;
      &lt;/bpmn:timerEventDefinition&gt;
    &lt;/bpmn:startEvent&gt;
    &lt;bpmn:serviceTask id=&quot;Activity_047mv6x&quot; name=&quot;Get users&quot; camunda:class=&quot;*.Cron&quot;&gt;
      &lt;bpmn:incoming&gt;Flow_1dfd8um&lt;/bpmn:incoming&gt;
      &lt;bpmn:outgoing&gt;Flow_19hnbhv&lt;/bpmn:outgoing&gt;
    &lt;/bpmn:serviceTask&gt;
  &lt;/bpmn:process&gt;
  &lt;bpmndi:BPMNDiagram id=&quot;BPMNDiagram_1&quot;&gt;
    &lt;bpmndi:BPMNPlane id=&quot;BPMNPlane_1&quot; bpmnElement=&quot;Process_1aegwvb&quot;&gt;
      &lt;bpmndi:BPMNEdge id=&quot;Flow_19hnbhv_di&quot; bpmnElement=&quot;Flow_19hnbhv&quot;&gt;
        &lt;di:waypoint x=&quot;370&quot; y=&quot;117&quot; /&gt;
        &lt;di:waypoint x=&quot;432&quot; y=&quot;117&quot; /&gt;
      &lt;/bpmndi:BPMNEdge&gt;
      &lt;bpmndi:BPMNEdge id=&quot;Flow_1dfd8um_di&quot; bpmnElement=&quot;Flow_1dfd8um&quot;&gt;
        &lt;di:waypoint x=&quot;215&quot; y=&quot;117&quot; /&gt;
        &lt;di:waypoint x=&quot;270&quot; y=&quot;117&quot; /&gt;
      &lt;/bpmndi:BPMNEdge&gt;
      &lt;bpmndi:BPMNShape id=&quot;Event_1vradpp_di&quot; bpmnElement=&quot;Event_1vradpp&quot;&gt;
        &lt;dc:Bounds x=&quot;432&quot; y=&quot;99&quot; width=&quot;36&quot; height=&quot;36&quot; /&gt;
      &lt;/bpmndi:BPMNShape&gt;
      &lt;bpmndi:BPMNShape id=&quot;Event_11i5xth_di&quot; bpmnElement=&quot;StartEvent_1&quot;&gt;
        &lt;dc:Bounds x=&quot;179&quot; y=&quot;99&quot; width=&quot;36&quot; height=&quot;36&quot; /&gt;
      &lt;/bpmndi:BPMNShape&gt;
      &lt;bpmndi:BPMNShape id=&quot;Activity_01expgb_di&quot; bpmnElement=&quot;Activity_047mv6x&quot;&gt;
        &lt;dc:Bounds x=&quot;270&quot; y=&quot;77&quot; width=&quot;100&quot; height=&quot;80&quot; /&gt;
      &lt;/bpmndi:BPMNShape&gt;
    &lt;/bpmndi:BPMNPlane&gt;
  &lt;/bpmndi:BPMNDiagram&gt;
&lt;/bpmn:definitions&gt;
  1. jar file with Authentication provider classes and class Cron added into folders

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

If I start this process manually in Camunda Webapp or via REST API, it works fine and make needful job. But every 5 minutes I see problem in logs .

  1. Where do I need to add this class into classpath? It is a docker image with some extra features, custom authentication provider and so on.

  2. Cron.java:

    public class Cron implements JavaDelegate {

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

    }

    24-Sep-2020 10:40:05.164 SEVERE [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16006 BPMN Stack Trace:
    Activity_047mv6x (activity-execute, ProcessInstance[4ed42252-fe52-11ea-9efd-12baf36f6a87])
    Activity_047mv6x, name=Get users
    ^
    |
    StartEvent_1

    24-Sep-2020 10:40:05.166 SEVERE [pool-2-thread-3] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 Exception while closing command context: ENGINE-09008 Exception while instantiating class '.Cron': ENGINE-09017 Cannot load class '.Cron': .Cron
    org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class '
    .Cron': ENGINE-09017 Cannot load class '*.Cron': *.Cron
    at org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:81)......................

    Caused by: java.lang.ClassNotFoundException: *.Cron
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:87)
    ... 92 more

答案1

得分: 1

Your process model contains a user task with implementation type Java Class.
The Java Class name is set to: *.Cron
So, when you run the process, the engine is trying to find and instantiate a class of this name.

Link to documentation

> 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.

You need to change the process model to reference a class which actually exists (Reference Link) or use another implementation approach.

Your Docker image is likely based on Camunda BPM run. In this distribution, additional jars can be placed in the userlib folder.
Link to Camunda BPM run documentation
However, since you do not seem to be well-versed in the Java world, you may want to consider a different approach to invoke your service. For instance, you could change the implementation of your service task to a script task or to an external service task.

Link to script task documentation
Link to external service task documentation

英文:

Your process model contains a user task with implementation type Java Class.
The Java Class name is set to: *.Cron
So, when you run the process the engine is trying to find and instantiate a class of this name.

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.

You need to change the process model to reference a class which actually exists (https://docs.camunda.org/manual/latest/reference/bpmn20/tasks/service-task/) or use another implementation approach.

Your Docker image is likely based on Camunda BPM run. In this distribution additional jars can be placed in the userlib folder.
https://docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/
However, since you do not seem to be right at home in the Java world, you may want to consider a different approach to invoke your service. You could for instance change the implementation of your service task to a script tasks or to an external service task

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

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

答案2

得分: -1

通过创建具有Cron类打包的独立模块来解决问题。
然后将其添加为另一个Web应用程序。

英文:

Solved problem by creating distinct module with Cron class packaging war.
And then add it as one more web application.

huangapple
  • 本文由 发表于 2020年9月24日 19:24:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64045453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定