在 Camunda 条件下使用 Spring Bean
Use Spring Bean in Camunda condition
我有一个 Camunda 流程,如下所示:
我使用专用网关在我的工作流程中创建一个分支:当一封电子邮件已经确认时我就继续,如果没有我想确认它。
为了实现这一点,我在序列流中添加了以下条件:
<!-- GATEWAY -->
<bpmn2:exclusiveGateway id="ExclusiveGateway_1" default="GO_TO_CONFIRM_EMAIL">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
<bpmn2:outgoing>GO_TO_CONFIRM_EMAIL</bpmn2:outgoing>
<bpmn2:outgoing>GO_TO_IDENTIFY_ORDER</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<!-- DEFAULT FLOW -->
<bpmn2:sequenceFlow id="GO_TO_CONFIRM_EMAIL" name="!confirmed" sourceRef="ExclusiveGateway_1" targetRef="CONFIRM_EMAIL"/>
<!-- FLOW WITH CONDITION -->
<bpmn2:sequenceFlow id="GO_TO_IDENTIFY_ORDER" name="confirmed" sourceRef="ExclusiveGateway_1" targetRef="IDENTIFY_ORDER">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${confirmEmailTaskAdapter.isConfirmed(CONFIRMED_ORDER_JSON)}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
但是,当我 运行 这样做时,我得到以下异常:
org.camunda.bpm.engine.ProcessEngineException: Cannot construct activity-execution mapping: there are more scope executions missing than explained by the flow scope hierarchy.
at org.camunda.bpm.engine.impl.pvm.runtime.LegacyBehavior.createActivityExecutionMapping(LegacyBehavior.java:294)
at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.createActivityExecutionMapping(PvmExecutionImpl.java:1211)
at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.createActivityExecutionMapping(PvmExecutionImpl.java:1144)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior$ErrorDeclarationFinder.collect(AbstractBpmnActivityBehavior.java:248)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior$ErrorDeclarationFinder.collect(AbstractBpmnActivityBehavior.java:223)
at org.camunda.bpm.engine.impl.tree.TreeWalker.walkUntil(TreeWalker.java:72)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.propagateError(AbstractBpmnActivityBehavior.java:124)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.propagateExceptionAsError(AbstractBpmnActivityBehavior.java:94)
at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior.execute(ServiceTaskExpressionActivityBehavior.java:64)
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:42)
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:27)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:134)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:494)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:484)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:464)
... and some more ...
但是,如果我将条件更改为非常简单的条件,则该过程有效:
<!-- THIS WORKS FINE -->
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${true}</bpmn2:conditionExpression>
我的 Spring Bean 看起来很正常:
@Component
public class ConfirmEmailTaskAdapter {
public boolean isConfirmed(String json) {
// bla bla bla
return true;
}
}
为什么在 Camunda 条件下使用我的 Spring Bean 不起作用?
既然对Thomas有所帮助,我将post我的上述评论作为答案,虽然它不是问题的技术解决方案。
不是解决方案,而是可能有助于解决问题的最佳实践:我们不使用动态服务调用来进行网关决策,只使用预评估的流程变量。因此,在您的情况下,为什么不让 Listener 甚至 serviceTask 确定确认值,将其写入流程变量,而不是仅在序列流上使用 ${isConfirmed} ...
我有一个 Camunda 流程,如下所示:
我使用专用网关在我的工作流程中创建一个分支:当一封电子邮件已经确认时我就继续,如果没有我想确认它。
为了实现这一点,我在序列流中添加了以下条件:
<!-- GATEWAY -->
<bpmn2:exclusiveGateway id="ExclusiveGateway_1" default="GO_TO_CONFIRM_EMAIL">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
<bpmn2:outgoing>GO_TO_CONFIRM_EMAIL</bpmn2:outgoing>
<bpmn2:outgoing>GO_TO_IDENTIFY_ORDER</bpmn2:outgoing>
</bpmn2:exclusiveGateway>
<!-- DEFAULT FLOW -->
<bpmn2:sequenceFlow id="GO_TO_CONFIRM_EMAIL" name="!confirmed" sourceRef="ExclusiveGateway_1" targetRef="CONFIRM_EMAIL"/>
<!-- FLOW WITH CONDITION -->
<bpmn2:sequenceFlow id="GO_TO_IDENTIFY_ORDER" name="confirmed" sourceRef="ExclusiveGateway_1" targetRef="IDENTIFY_ORDER">
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${confirmEmailTaskAdapter.isConfirmed(CONFIRMED_ORDER_JSON)}</bpmn2:conditionExpression>
</bpmn2:sequenceFlow>
但是,当我 运行 这样做时,我得到以下异常:
org.camunda.bpm.engine.ProcessEngineException: Cannot construct activity-execution mapping: there are more scope executions missing than explained by the flow scope hierarchy.
at org.camunda.bpm.engine.impl.pvm.runtime.LegacyBehavior.createActivityExecutionMapping(LegacyBehavior.java:294)
at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.createActivityExecutionMapping(PvmExecutionImpl.java:1211)
at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.createActivityExecutionMapping(PvmExecutionImpl.java:1144)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior$ErrorDeclarationFinder.collect(AbstractBpmnActivityBehavior.java:248)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior$ErrorDeclarationFinder.collect(AbstractBpmnActivityBehavior.java:223)
at org.camunda.bpm.engine.impl.tree.TreeWalker.walkUntil(TreeWalker.java:72)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.propagateError(AbstractBpmnActivityBehavior.java:124)
at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.propagateExceptionAsError(AbstractBpmnActivityBehavior.java:94)
at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior.execute(ServiceTaskExpressionActivityBehavior.java:64)
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:42)
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:27)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:134)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:494)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:484)
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:464)
... and some more ...
但是,如果我将条件更改为非常简单的条件,则该过程有效:
<!-- THIS WORKS FINE -->
<bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${true}</bpmn2:conditionExpression>
我的 Spring Bean 看起来很正常:
@Component
public class ConfirmEmailTaskAdapter {
public boolean isConfirmed(String json) {
// bla bla bla
return true;
}
}
为什么在 Camunda 条件下使用我的 Spring Bean 不起作用?
既然对Thomas有所帮助,我将post我的上述评论作为答案,虽然它不是问题的技术解决方案。
不是解决方案,而是可能有助于解决问题的最佳实践:我们不使用动态服务调用来进行网关决策,只使用预评估的流程变量。因此,在您的情况下,为什么不让 Listener 甚至 serviceTask 确定确认值,将其写入流程变量,而不是仅在序列流上使用 ${isConfirmed} ...