Camunda - 动态创建的模型在调用 TaskListener 类时导致“java.lang.ClassNotFoundException”

问题描述 投票:0回答:2

我有一系列用 XML 定义的模型。我们现在需要动态创建模型,而不需要 XML 文件和任何重新启动 Camunda Web 应用程序。

我已经实现了动态模型并进行了部署(modelInstance 是一个 BpmnModelInstance 对象):

BpmPlatform.getProcessEngineService()
                    .getProcessEngine("default")
                    .getRepositoryService()
                    .createDeployment().addModelInstance("bpmn", modelInstance)
                    .deploy();

但是当部署并实例化模型时,会抛出以下错误:

Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class 'org.camunda.bpm.utility.AssignmentAPINotify': ENGINE-09017 Cannot load class 'org.camunda.bpm.utility.AssignmentAPINotify': org.camunda.bpm.utility.AssignmentAPINotify
    at org.camunda.bpm.engine.impl.util.EngineUtilLogger.exceptionWhileInstantiatingClass(EngineUtilLogger.java:78)
    at org.camunda.bpm.engine.impl.util.ClassDelegateUtil.instantiateDelegate(ClassDelegateUtil.java:50)
    at org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener.getTaskListenerInstance(ClassDelegateTaskListener.java:54)
    at org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener.notify(ClassDelegateTaskListener.java:42)
    at org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation.invoke(TaskListenerInvocation.java:41)
    at org.camunda.bpm.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:54)
    at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocationInContext(DefaultDelegateInterceptor.java:87)
    at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:59)
    at org.camunda.bpm.engine.impl.persistence.entity.TaskEntity.fireEvent(TaskEntity.java:956)
    ... 119 more
Caused by: org.camunda.bpm.engine.ClassLoadingException: ENGINE-09017 Cannot load class 'org.camunda.bpm.utility.AssignmentAPINotify': org.camunda.bpm.utility.AssignmentAPINotify
    at org.camunda.bpm.engine.impl.util.EngineUtilLogger.classLoadingException(EngineUtilLogger.java:135)
    at org.camunda.bpm.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:107)
    at org.camunda.bpm.engine.impl.util.ClassDelegateUtil.instantiateDelegate(ClassDelegateUtil.java:42)
    ... 126 more
Caused by: java.lang.ClassNotFoundException: org.camunda.bpm.utility.AssignmentAPINotify
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
    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:84)
    ... 127 more

如果我将模型保存为 XML 并重新启动,就不会有任何问题。

我一直在查看是否deploymentBuilder.addClasspathResource("");是解决方案,但似乎没有任何效果!

java bpmn camunda
2个回答
0
投票

传递给

DeploymentBuilder#addModelInstance
的“resourceName”是动态创建的模型在从文件系统部署时将具有的文件名。这有点不直观,但 Camunda 部署机制需要...一个好的规则是将
.bpmn
附加到您的 processDefinitionKey,所以这应该可以工作:

.createDeployment()
      .addModelInstance(
             "myProcess.bpmn", 
             BPMN.createExecutableProcess("myProcess")
                  ....
             .done()
      ).deploy();

0
投票

我通过使用管理服务将部署注册到流程应用程序解决了这个问题

            ProcessEngine processEngine = BpmPlatform.getProcessEngineService().getDefaultProcessEngine();
            DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
            deploymentBuilder = deploymentBuilder.addModelInstance(name, modelInstance);
            Deployment deployment = deploymentBuilder.deploy();
                        
            ManagementService managementService = processEngine.getManagementService();
            managementService.registerProcessApplication(deployment.getId(), PROCESS_APPLICATION_REFERENCE);

这个问题在 Camunda 论坛的帮助下解决了。

© www.soinside.com 2019 - 2024. All rights reserved.